-
-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
features to pause batch execution #1323
Draft
pgvsalamander
wants to merge
21
commits into
bensheldon:main
Choose a base branch
from
pgvsalamander:feat/paused-batch-execution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6d4d4a3
wip
pgvsalamander 9d9c784
jobs queued within a paused batch are automatically paused
pgvsalamander 508e556
rm irrelevant changes
pgvsalamander ec11c44
appease linter
pgvsalamander e368b3c
remove byebug
pgvsalamander 1803f8b
revert dev change that was breaking tests
pgvsalamander f949fd0
reworked pause extension to be included globally
pgvsalamander 4998922
comment
pgvsalamander bf33a9b
todo
pgvsalamander 10e1404
linter - use load hook
pgvsalamander cceee54
added a stopgap and TODO for an edge case
pgvsalamander f66c5d7
fixed a issue that would cause the jobs-to-unpause query to break and…
pgvsalamander 84527cb
working on tests
pgvsalamander 749b464
cleanup
pgvsalamander bce4daf
fixed test failures caused by scheduled_at being nil, need to confirm…
pgvsalamander 18b58ff
reverted local-only changes
pgvsalamander 768ab27
linter
pgvsalamander a31084e
repaired tests
pgvsalamander e27b9f5
cleanup
pgvsalamander 1f266db
rm comment as tests seem to depend on line numbering
pgvsalamander 7c599a7
relaxed how close created_at and scheduled_at must be to pass a test
pgvsalamander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ class OtherJob < ApplicationJob | |
JobError = Class.new(StandardError) | ||
|
||
def perform(*) | ||
# raise 'nope' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob | ||
module ActiveJobExtensions | ||
# Allows configuring whether the job should start 'paused' when a job is enqueued. | ||
# Configuration will apply either globally to the Job Class, or individually to jobs | ||
# on initial enqueue and subsequent retries. | ||
# | ||
# @example | ||
# class MyJob < ApplicationJob | ||
# self.good_job_paused = true | ||
# end | ||
# | ||
# # Or, configure jobs individually to not notify: | ||
# MyJob.set(good_job_paused: true).perform_later | ||
# | ||
# See also - GoodJob:Batch#new's `paused` option | ||
|
||
module Pauseable | ||
extend ActiveSupport::Concern | ||
|
||
module Prepends | ||
def enqueue(options = {}) | ||
self.good_job_paused = options[:good_job_paused] if options.key?(:good_job_paused) | ||
super | ||
end | ||
|
||
# good_job_paused is intentionally excluded from the serialized params so we fully rely on the scheduled_at value once the job is enqueued | ||
# TODO: remove before merge | ||
# def serialize | ||
# super.tap do |job_data| | ||
# # job_data["good_job_paused"] = good_job_paused unless good_job_paused.nil? | ||
# end | ||
# end | ||
|
||
# def deserialize(job_data) | ||
# super | ||
# self.good_job_paused = job_data["good_job_paused"] | ||
# end | ||
end | ||
|
||
included do | ||
prepend Prepends | ||
class_attribute :good_job_paused, instance_accessor: false, instance_predicate: false, default: nil | ||
attr_accessor :good_job_paused | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Jobs can be paused through batches which rely on good_job_paused being available, so this must be included globally | ||
ActiveSupport.on_load(:active_job) { include GoodJob::ActiveJobExtensions::Pauseable } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Indicate paused status in the jobs dashboard | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really want to support (at least right now, initially) having a special property of a batch ("paused") have a side effect or meaning to the library; I consider them arbitrary application data.
I realize it makes it a little less optimal to say: "To create a paused batch, enqueue any job that is paused" but I think that's a fine workaround for now. I sort of see the order here being:
scheduled_at
to be nilAnd honestly, other than that, this looks great. I can help polish stuff up if whenever you're ok with where things are at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be open to storing a batch's paused state in a separate column/hash/etc to avoid the interference, or would you prefer to remove that entirely?
re: unpausing interface
What functionality did you have in mind for the dashboard? I could see a use for unpausing jobs by hand if we also had the capability to pause jobs by hand, but if they're only paused programmatically I don't see as much benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to defer that. So not one way or another in perpetuity, but for right now it looks like we have a path to allow for a pausing feature without changing any existing interfaces or database columns. This is mostly about my personal ability to handle complexity, not the technical stuff.
We'd need to show that the jobs are in a paused state on the dashboard, to answer the question of "why isn't this job running?" And it would be nice to also add options (simple ones) to pause and unpause through the UI.
On the programmitic side, I think the
pause
/unpause
methods should be class methods on the job. e.g.OtherJob.unpause(jobs_or_ids)