Skip to content
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

Bugfix support overlap option #601

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Resque Scheduler authors
- Nickolas Means
- Olek Janiszewski
- Olivier Brisse
- Peter Retzlaff
- Petteri Räty
- Phil Cohen
- Rob Olson
Expand Down
51 changes: 37 additions & 14 deletions lib/resque/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,9 @@ def handle_shutdown
# Enqueues a job based on a config hash
def enqueue_from_config(job_config)
args = job_config['args'] || job_config[:args]

klass_name = job_config['class'] || job_config[:class]
begin
klass = Resque::Scheduler::Util.constantize(klass_name)
rescue NameError
klass = klass_name
end

params = args.is_a?(Hash) ? [args] : Array(args)
queue = job_config['queue'] ||
job_config[:queue] ||
Resque.queue_from_class(klass)
klass, klass_name, queue = queue_info_from(job_config)

# Support custom job classes like those that inherit from
# Resque::JobWithStatus (resque-status)
job_klass = job_config['custom_job_class']
Expand Down Expand Up @@ -419,11 +410,43 @@ def logger

private

def queue_info_from(config)
klass_name = config['class'] || config[:class]
begin
klass = Resque::Scheduler::Util.constantize(klass_name)
rescue NameError
klass = klass_name
end

queue_name = config['queue'] || config[:queue] || Resque.queue_from_class(klass)
[klass, klass_name, queue_name]
end

def in_progress?(queue_name)
currently_processing = Resque::Worker.working.map(&:job).any? do |job|
job['queue'] == queue_name.to_s
end
return true if currently_processing

Resque.peek(queue_name, 0, 5000).any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this jazz about?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to figure out, if there's either a worker still working on the scheduled job or there's already one in the queue.
Granted, it's awkward. I updated the PR.

end

def should_enqueue?(config)
allow_overlap = (config[:overlap] != false && config['overlap'] != false)
_, _, queue_name = queue_info_from(config)

allow_overlap || !in_progress?(queue_name)
end

def enqueue_recurring(name, config)
if master?
log! "queueing #{config['class']} (#{name})"
Resque.last_enqueued_at(name, Time.now.to_s)
enqueue(config)
if should_enqueue?(config)
log! "queueing #{config['class']} (#{name})"
Resque.last_enqueued_at(name, Time.now.to_s)
enqueue(config)
else
log! "No overlap allowed. Not enqueueing #{config['class']} (#{name})"
end
end
end

Expand Down