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 39 40 |
# File 'lib/angry_batch/batch.rb', line 34 def expired completed = where('state = ? AND updated_at < ?', :completed, 2.days.ago) failed = where('state = ? AND updated_at < ?', :failed, 4.weeks.ago) pending = where('state = ? AND updated_at < ?', :pending, 4.weeks.ago) completed.or(failed).or(pending) end |
Instance Method Details
#check_status_of_jobs ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/angry_batch/batch.rb', line 43 def check_status_of_jobs return unless pending? return unless jobs_count == jobs.finished.count self.finished_at = Time.current if jobs.failed.none? update! state: 'completed' enqueue_handlers(complete_handlers) else update! state: 'failed' enqueue_handlers(failure_handlers) end end |