Class: OnlineMigrations::BackgroundMigrations::MigrationJob
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- OnlineMigrations::BackgroundMigrations::MigrationJob
- Defined in:
- lib/online_migrations/background_migrations/migration_job.rb
Constant Summary collapse
- STATUSES =
[ :enqueued, :running, :errored, :failed, :succeeded, :cancelled, ]
Instance Method Summary collapse
- #attempts_exceeded? ⇒ Boolean
-
#retry ⇒ Object
Mark this job as ready to be processed again.
-
#stuck? ⇒ Boolean
Whether the job is considered stuck (is running for some configured time).
Instance Method Details
#attempts_exceeded? ⇒ Boolean
60 61 62 |
# File 'lib/online_migrations/background_migrations/migration_job.rb', line 60 def attempts_exceeded? attempts >= max_attempts end |
#retry ⇒ Object
Mark this job as ready to be processed again.
This is used when retrying failed jobs.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/online_migrations/background_migrations/migration_job.rb', line 68 def retry if failed? transaction do update!( status: self.class.statuses[:enqueued], attempts: 0, started_at: nil, finished_at: nil, error_class: nil, error_message: nil, backtrace: nil ) migration.enqueued! if migration.failed? end true else false end end |
#stuck? ⇒ Boolean
Whether the job is considered stuck (is running for some configured time).
55 56 57 58 |
# File 'lib/online_migrations/background_migrations/migration_job.rb', line 55 def stuck? timeout = OnlineMigrations.config.background_migrations.stuck_jobs_timeout running? && updated_at <= timeout.seconds.ago end |