| ... | @@ -5,14 +5,14 @@ module HasStatus |
... | @@ -5,14 +5,14 @@ module HasStatus |
|
|
|
|
|
|
|
DEFAULT_STATUS = 'created'.freeze
|
|
DEFAULT_STATUS = 'created'.freeze
|
|
|
BLOCKED_STATUS = %w[manual scheduled].freeze
|
|
BLOCKED_STATUS = %w[manual scheduled].freeze
|
|
|
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped manual scheduled].freeze
|
|
AVAILABLE_STATUSES = %w[created preparing pending running success failed canceled skipped manual scheduled].freeze
|
|
|
STARTED_STATUSES = %w[running success failed skipped manual scheduled].freeze
|
|
STARTED_STATUSES = %w[running success failed skipped manual scheduled].freeze
|
|
|
ACTIVE_STATUSES = %w[pending running].freeze
|
|
ACTIVE_STATUSES = %w[preparing pending running].freeze
|
|
|
COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
|
|
COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
|
|
|
ORDERED_STATUSES = %w[failed pending running manual scheduled canceled success skipped created].freeze
|
|
ORDERED_STATUSES = %w[failed preparing pending running manual scheduled canceled success skipped created].freeze
|
|
|
STATUSES_ENUM = { created: 0, pending: 1, running: 2, success: 3,
|
|
STATUSES_ENUM = { created: 0, pending: 1, running: 2, success: 3,
|
|
|
failed: 4, canceled: 5, skipped: 6, manual: 7,
|
|
failed: 4, canceled: 5, skipped: 6, manual: 7,
|
|
|
scheduled: 8 }.freeze
|
|
scheduled: 8, preparing: 9 }.freeze
|
|
|
|
|
|
|
|
UnknownStatusError = Class.new(StandardError)
|
|
UnknownStatusError = Class.new(StandardError)
|
|
|
|
|
|
| ... | @@ -26,6 +26,7 @@ module HasStatus |
... | @@ -26,6 +26,7 @@ module HasStatus |
|
|
success = scope_relevant.success.select('count(*)').to_sql
|
|
success = scope_relevant.success.select('count(*)').to_sql
|
|
|
manual = scope_relevant.manual.select('count(*)').to_sql
|
|
manual = scope_relevant.manual.select('count(*)').to_sql
|
|
|
scheduled = scope_relevant.scheduled.select('count(*)').to_sql
|
|
scheduled = scope_relevant.scheduled.select('count(*)').to_sql
|
|
|
|
preparing = scope_relevant.preparing.select('count(*)').to_sql
|
|
|
pending = scope_relevant.pending.select('count(*)').to_sql
|
|
pending = scope_relevant.pending.select('count(*)').to_sql
|
|
|
running = scope_relevant.running.select('count(*)').to_sql
|
|
running = scope_relevant.running.select('count(*)').to_sql
|
|
|
skipped = scope_relevant.skipped.select('count(*)').to_sql
|
|
skipped = scope_relevant.skipped.select('count(*)').to_sql
|
| ... | @@ -37,12 +38,14 @@ module HasStatus |
... | @@ -37,12 +38,14 @@ module HasStatus |
|
|
WHEN (#{builds})=(#{skipped}) THEN 'skipped'
|
|
WHEN (#{builds})=(#{skipped}) THEN 'skipped'
|
|
|
WHEN (#{builds})=(#{success}) THEN 'success'
|
|
WHEN (#{builds})=(#{success}) THEN 'success'
|
|
|
WHEN (#{builds})=(#{created}) THEN 'created'
|
|
WHEN (#{builds})=(#{created}) THEN 'created'
|
|
|
|
WHEN (#{builds})=(#{preparing}) THEN 'preparing'
|
|
|
WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'success'
|
|
WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'success'
|
|
|
WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
|
|
WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
|
|
|
WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'
|
|
WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'
|
|
|
WHEN (#{running})+(#{pending})>0 THEN 'running'
|
|
WHEN (#{running})+(#{pending})>0 THEN 'running'
|
|
|
WHEN (#{manual})>0 THEN 'manual'
|
|
WHEN (#{manual})>0 THEN 'manual'
|
|
|
WHEN (#{scheduled})>0 THEN 'scheduled'
|
|
WHEN (#{scheduled})>0 THEN 'scheduled'
|
|
|
|
WHEN (#{preparing})>0 THEN 'preparing'
|
|
|
WHEN (#{created})>0 THEN 'running'
|
|
WHEN (#{created})>0 THEN 'running'
|
|
|
ELSE 'failed'
|
|
ELSE 'failed'
|
|
|
END)"
|
|
END)"
|
| ... | @@ -70,6 +73,7 @@ module HasStatus |
... | @@ -70,6 +73,7 @@ module HasStatus |
|
|
|
|
|
|
|
state_machine :status, initial: :created do
|
|
state_machine :status, initial: :created do
|
|
|
state :created, value: 'created'
|
|
state :created, value: 'created'
|
|
|
|
state :preparing, value: 'preparing'
|
|
|
state :pending, value: 'pending'
|
|
state :pending, value: 'pending'
|
|
|
state :running, value: 'running'
|
|
state :running, value: 'running'
|
|
|
state :failed, value: 'failed'
|
|
state :failed, value: 'failed'
|
| ... | @@ -81,6 +85,7 @@ module HasStatus |
... | @@ -81,6 +85,7 @@ module HasStatus |
|
|
end
|
|
end
|
|
|
|
|
|
|
|
scope :created, -> { where(status: 'created') }
|
|
scope :created, -> { where(status: 'created') }
|
|
|
|
scope :preparing, -> { where(status: 'preparing') }
|
|
|
scope :relevant, -> { where(status: AVAILABLE_STATUSES - ['created']) }
|
|
scope :relevant, -> { where(status: AVAILABLE_STATUSES - ['created']) }
|
|
|
scope :running, -> { where(status: 'running') }
|
|
scope :running, -> { where(status: 'running') }
|
|
|
scope :pending, -> { where(status: 'pending') }
|
|
scope :pending, -> { where(status: 'pending') }
|
| ... | @@ -90,14 +95,14 @@ module HasStatus |
... | @@ -90,14 +95,14 @@ module HasStatus |
|
|
scope :skipped, -> { where(status: 'skipped') }
|
|
scope :skipped, -> { where(status: 'skipped') }
|
|
|
scope :manual, -> { where(status: 'manual') }
|
|
scope :manual, -> { where(status: 'manual') }
|
|
|
scope :scheduled, -> { where(status: 'scheduled') }
|
|
scope :scheduled, -> { where(status: 'scheduled') }
|
|
|
scope :alive, -> { where(status: [:created, :pending, :running]) }
|
|
scope :alive, -> { where(status: [:created, :preparing, :pending, :running]) }
|
|
|
scope :created_or_pending, -> { where(status: [:created, :pending]) }
|
|
scope :created_or_pending, -> { where(status: [:created, :pending]) }
|
|
|
scope :running_or_pending, -> { where(status: [:running, :pending]) }
|
|
scope :running_or_pending, -> { where(status: [:running, :pending]) }
|
|
|
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
|
|
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
|
|
|
scope :failed_or_canceled, -> { where(status: [:failed, :canceled]) }
|
|
scope :failed_or_canceled, -> { where(status: [:failed, :canceled]) }
|
|
|
|
|
|
|
|
scope :cancelable, -> do
|
|
scope :cancelable, -> do
|
|
|
where(status: [:running, :pending, :created, :scheduled])
|
|
where(status: [:running, :preparing, :pending, :created, :scheduled])
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
| ... | |
... | |
| ... | | ... | |