Class: AngryBatch::Batch
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AngryBatch::Batch
- Defined in:
- lib/angry_batch/batch.rb
Overview
Schema Information
Table name: angry_batch_batches
id :bigint(8) not null, primary key
complete_handlers :jsonb not null
failure_handlers :jsonb not null
finished_at :datetime
jobs_count :integer default(0), not null
label :string
state :string default("scheduling"), not null
created_at :datetime not null
updated_at :datetime not null
Indexes
index_angry_batch_batches_on_state (state)
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.expired ⇒ Object
34 35 36 37 38 |
# File 'lib/angry_batch/batch.rb', line 34 def expired completed.where(updated_at: ...2.days.ago) .or(failed.where(updated_at: ...4.weeks.ago)) .or(pending.where(updated_at: ...4.weeks.ago)) end |
Instance Method Details
#check_status_of_jobs ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/angry_batch/batch.rb', line 41 def check_status_of_jobs handlers_to_enqueue = with_lock do return unless pending? return unless jobs_count == jobs.finished.count self.finished_at = Time.current if jobs.failed.none? update! state: 'completed' complete_handlers else update! state: 'failed' failure_handlers end end enqueue_handlers(handlers_to_enqueue) end |