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

Disable extensions when Resque.inline? == true #12

Merged
merged 1 commit into from Sep 2, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/resque-ext/job.rb
Expand Up @@ -12,19 +12,23 @@ class Job
# after Resque::Job.create has called Resque.push
#
def self.create_with_loner(queue, klass, *args)
item = { :class => klass.to_s, :args => args }
return "EXISTED" if Resque::Plugins::Loner::Helpers.loner_queued?(queue, item)
job = create_without_loner(queue, klass, *args)
Resque::Plugins::Loner::Helpers.mark_loner_as_queued(queue, item)
job
if Resque.inline?
Copy link
Member

Choose a reason for hiding this comment

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

I'd personally do it like this:

def self.create_with_loner(queue, klass, *args)
  return create_without_loner(queue, klass, *args) if Resque.inline?
  ...
end

But will merge like that unless you want to change it ;)

create_without_loner(queue, klass, *args)
else
item = { :class => klass.to_s, :args => args }
return "EXISTED" if Resque::Plugins::Loner::Helpers.loner_queued?(queue, item)
job = create_without_loner(queue, klass, *args)
Resque::Plugins::Loner::Helpers.mark_loner_as_queued(queue, item)
job
end
end

#
# Overwriting original reserve method to mark an item as unqueued
#
def self.reserve_with_loner(queue)
item = reserve_without_loner(queue)
Resque::Plugins::Loner::Helpers.mark_loner_as_unqueued( queue, item ) if item
Resque::Plugins::Loner::Helpers.mark_loner_as_unqueued( queue, item ) if item && !Resque.inline?
item
end

Expand All @@ -35,7 +39,7 @@ def self.reserve_with_loner(queue)
# as the original method Resque::Job.destroy. Couldn't make it any dry'er.
#
def self.destroy_with_loner(queue, klass, *args)
Resque::Plugins::Loner::Helpers.job_destroy(queue, klass, *args)
Resque::Plugins::Loner::Helpers.job_destroy(queue, klass, *args) unless Resque.inline?
destroy_without_loner(queue, klass, *args)
end

Expand Down