rosa-build/app/models/repository_status.rb

84 lines
3.5 KiB
Ruby
Raw Normal View History

class RepositoryStatus < ActiveRecord::Base
2013-08-27 17:27:22 +01:00
include Modules::Models::FileStoreClean
include Modules::Models::RegenerationStatus
WAITING_FOR_RESIGN = 300
PUBLISH = 400
RESIGN = 500
WAITING_FOR_RESIGN_AFTER_PUBLISH = 600
WAITING_FOR_RESIGN_AFTER_REGENERATION = 700
WAITING_FOR_REGENERATION_AFTER_PUBLISH = 800
WAITING_FOR_REGENERATION_AFTER_RESIGN = 900
WAITING_FOR_RESIGN_AND_REGENERATION_AFTER_PUBLISH = 1000
WAITING_FOR_RESIGN_AND_REGENERATION = 1100
2014-01-21 04:51:49 +00:00
HUMAN_STATUSES = HUMAN_STATUSES.clone.merge({
WAITING_FOR_RESIGN => :waiting_for_resign,
PUBLISH => :publish,
RESIGN => :resign,
WAITING_FOR_RESIGN_AFTER_PUBLISH => :waiting_for_resign_after_publish,
WAITING_FOR_RESIGN_AFTER_REGENERATION => :waiting_for_resign_after_regeneration,
WAITING_FOR_REGENERATION_AFTER_PUBLISH => :waiting_for_regeneration_after_publish,
WAITING_FOR_REGENERATION_AFTER_RESIGN => :waiting_for_regeneration_after_resign,
WAITING_FOR_RESIGN_AND_REGENERATION_AFTER_PUBLISH => :waiting_for_resign_and_regeneration_after_publish,
WAITING_FOR_RESIGN_AND_REGENERATION => :waiting_for_resign_and_regeneration
}).freeze
belongs_to :platform
belongs_to :repository
2014-01-21 04:51:49 +00:00
validates :repository_id, :platform_id, presence: true
validates :repository_id, uniqueness: {scope: :platform_id}
attr_accessible :platform_id, :repository_id
scope :platform_ready, -> { where(platforms: {status: READY}).joins(:platform) }
scope :for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) }
scope :for_resign, -> { where(status: [WAITING_FOR_RESIGN, WAITING_FOR_RESIGN_AND_REGENERATION]) }
scope :not_ready, -> { where('repository_statuses.status != ?', READY) }
2014-01-21 04:51:49 +00:00
state_machine :status, initial: :ready do
event :ready do
transition [:regenerating, :publish, :resign] => :ready
transition [:waiting_for_resign_after_publish, :waiting_for_resign_after_regeneration] => :waiting_for_resign
transition [:waiting_for_regeneration_after_publish, :waiting_for_regeneration_after_resign] => :waiting_for_regeneration
2014-01-21 04:51:49 +00:00
transition waiting_for_resign_and_regeneration_after_publish: :waiting_for_resign_and_regeneration
end
event :regenerate do
2014-01-21 04:51:49 +00:00
transition ready: :waiting_for_regeneration
transition publish: :waiting_for_regeneration_after_publish
transition resign: :waiting_for_regeneration_after_resign
transition waiting_for_resign_after_publish: :waiting_for_resign_and_regeneration_after_publish
transition waiting_for_resign: :waiting_for_resign_and_regeneration
end
event :start_regeneration do
2014-01-21 04:51:49 +00:00
transition waiting_for_regeneration: :regenerating
transition waiting_for_resign_and_regeneration: :waiting_for_resign_after_regeneration
end
event :resign do
2014-01-21 04:51:49 +00:00
transition ready: :waiting_for_resign
transition publish: :waiting_for_resign_after_publish
transition waiting_for_regeneration: :waiting_for_resign_and_regeneration
transition waiting_for_regeneration_after_publish: :waiting_for_resign_and_regeneration_after_publish
transition regenerating: :waiting_for_resign_after_regeneration
end
event :start_resign do
2014-01-21 04:51:49 +00:00
transition waiting_for_resign: :resign
transition waiting_for_resign_and_regeneration: :waiting_for_regeneration_after_resign
end
event :publish do
2014-01-21 04:51:49 +00:00
transition ready: :publish
end
HUMAN_STATUSES.each do |code,name|
2014-01-21 04:51:49 +00:00
state name, value: code
end
end
end