-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use after hook #10
base: master
Are you sure you want to change the base?
Use after hook #10
Changes from 1 commit
58ddb41
6ab7620
28d590c
c88a3d3
bda08ea
0c86aae
ccfea33
3b8db90
b9a8a92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,14 @@ def ttl | |
def lock_after_execution_period | ||
@lock_after_execution_period ||= 0 | ||
end | ||
|
||
# We want this to run first in before_enqueue_hooks (which are alpha sorted), so name appropriately | ||
def before_enqueue_001_solo_job(*args) | ||
queue_name = self.instance_variable_get(:@queue) | ||
item = { class: self.to_s, args: args } | ||
!ResqueSolo::Queue.queued?(queue_name, item) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we write this all as one line?
|
||
end | ||
|
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ class ResqueTest < MiniTest::Spec | |
it "enqueues normal jobs" do | ||
Resque.enqueue FakeJob, "x" | ||
Resque.enqueue FakeJob, "x" | ||
assert_equal 2, Resque.size(:normal) | ||
queue_name = FakeJob.instance_variable_get(:@queue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all these tests, I prefer to simply hard-code the queue name rather than accessing an internal instance variable. So don't change the tests to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, should be good now I think... I haven't yet figured out the workflow to rebase and squash commits yet so let me know if I need to figure out how to make that happen. |
||
assert_equal 2, Resque.size(queue_name) | ||
end | ||
|
||
it "is not able to report if a non-unique job was enqueued" do | ||
|
@@ -26,19 +27,25 @@ class ResqueTest < MiniTest::Spec | |
describe "#enqueue_to" do | ||
describe "non-unique job" do | ||
it "should return true if job was enqueued" do | ||
assert Resque.enqueue_to(:normal, FakeJob) | ||
assert Resque.enqueue_to(:normal, FakeJob) | ||
queue_name = FakeJob.instance_variable_get(:@queue) | ||
assert Resque.enqueue_to(queue_name, FakeJob) | ||
assert Resque.enqueue_to(queue_name, FakeJob) | ||
end | ||
end | ||
|
||
describe "unique job" do | ||
before do | ||
@queue_name = FakeUniqueJob.instance_variable_get(:@queue) | ||
end | ||
|
||
it "should return true if job was enqueued" do | ||
assert Resque.enqueue_to(:normal, FakeUniqueJob) | ||
assert Resque.enqueue_to(@queue_name, FakeUniqueJob) | ||
end | ||
|
||
it "should return nil if job already existed" do | ||
Resque.enqueue_to(:normal, FakeUniqueJob) | ||
assert_nil Resque.enqueue_to(:normal, FakeUniqueJob) | ||
Resque.enqueue_to(@queue_name, FakeUniqueJob) | ||
assert Resque.enqueued?(FakeUniqueJob) | ||
assert_nil Resque.enqueue_to(@queue_name, FakeUniqueJob) | ||
end | ||
end | ||
end | ||
|
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.
Really excited to find resque_solo, the unreleased changes to make it not call after_enqueue_hooks if the job was not created, and this PR which makes the implementation hook based.
Why does the order of execution of before_enqueue hooks matter?
All before_enqueue_hooks will be invoked by Resque.enqueue_to, regardless of the result of any individual hook. So, it isn't clear to me why the order the hooks are invoked would matter.
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.
Yep, you're totally right. I just removed the misleading comment and name.