forked from tobi/delayed_job
-
Notifications
You must be signed in to change notification settings - Fork 956
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to set queue priority via queue_attributes. Updated worke…
…r to pull from worker prior to setting job priority to default priority.
- Loading branch information
1 parent
3b31ffd
commit 3f198bc
Showing
8 changed files
with
81 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec| | |
spec.description = 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.' | ||
spec.email = ['[email protected]'] | ||
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job.gemspec] | ||
spec.files += Dir.glob('{contrib,lib,recipes,spec}/**/*') | ||
spec.files += Dir.glob('{contrib,lib,recipes,spec}/**/*') # rubocop:disable SpaceAroundOperators | ||
spec.homepage = 'https://github.com/collectiveidea/delayed_job' | ||
spec.licenses = ['MIT'] | ||
spec.name = 'delayed_job' | ||
|
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,51 @@ | ||
module Delayed | ||
module Backend | ||
class JobPreparer | ||
attr_reader :options, :args | ||
|
||
def initialize(*args) | ||
@options = args.extract_options! | ||
@args = args | ||
end | ||
|
||
def prepare | ||
set_payload | ||
set_queue_name | ||
set_priority | ||
handle_deprecation | ||
options | ||
end | ||
|
||
private | ||
|
||
def set_payload | ||
options[:payload_object] ||= args.shift | ||
end | ||
|
||
def set_queue_name | ||
if options[:queue].nil? && options[:payload_object].respond_to?(:queue_name) | ||
options[:queue] = options[:payload_object].queue_name | ||
else | ||
options[:queue] ||= Delayed::Worker.default_queue_name | ||
end | ||
end | ||
|
||
def set_priority | ||
options[:priority] ||= Delayed::Worker.default_priority | ||
queue_attributes = Delayed::Worker.queue_attributes.select { |queue| queue[:name].to_s == options[:queue] } | ||
options[:priority] = queue_attributes.first[:priority] if queue_attributes.any? | ||
end | ||
|
||
def handle_deprecation | ||
if args.size > 0 | ||
warn '[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at.' | ||
options[:priority] = args.first || options[:priority] | ||
options[:run_at] = args[1] | ||
end | ||
|
||
return if options[:payload_object].respond_to?(:perform) | ||
raise ArgumentError, 'Cannot enqueue items which do not respond to perform' | ||
end | ||
end | ||
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
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