2013-08-22 17:12:54 +01:00
|
|
|
class RepositoryStatus < ActiveRecord::Base
|
2013-08-27 17:27:22 +01:00
|
|
|
include Modules::Models::FileStoreClean
|
|
|
|
include Modules::Models::RegenerationStatus
|
2013-08-23 19:58:29 +01:00
|
|
|
|
|
|
|
WAITING_FOR_RESIGN = 300
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-22 17:12:54 +01:00
|
|
|
|
2013-08-22 22:02:24 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
HUMAN_STATUSES = HUMAN_STATUSES.clone.merge({
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-23 19:58:29 +01:00
|
|
|
}).freeze
|
2013-08-22 22:02:24 +01:00
|
|
|
|
|
|
|
belongs_to :platform
|
|
|
|
belongs_to :repository
|
2013-08-22 17:12:54 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
validates :repository_id, :platform_id, presence: true
|
|
|
|
validates :repository_id, uniqueness: {scope: :platform_id}
|
2013-08-22 17:12:54 +01:00
|
|
|
|
2013-08-23 19:58:29 +01:00
|
|
|
attr_accessible :platform_id, :repository_id
|
2013-08-22 17:12:54 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
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])
|
2013-08-23 15:24:01 +01:00
|
|
|
scope :not_ready, where('repository_statuses.status != ?', READY)
|
2013-08-22 22:02:24 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
state_machine :status, initial: :ready do
|
2013-08-22 17:12:54 +01:00
|
|
|
event :ready do
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-22 17:12:54 +01:00
|
|
|
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
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-22 17:12:54 +01:00
|
|
|
end
|
|
|
|
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
2013-08-22 22:02:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
event :publish do
|
2014-01-21 04:51:49 +00:00
|
|
|
transition ready: :publish
|
2013-08-22 17:12:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
HUMAN_STATUSES.each do |code,name|
|
2014-01-21 04:51:49 +00:00
|
|
|
state name, value: code
|
2013-08-22 17:12:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-23 19:58:29 +01:00
|
|
|
end
|