Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Job run chain callbacks complete

added before_ensure and after_ensure. these work in similar fashion to before_invoke and other callbacks. Methods registered with before_ensure or after_ensure are guarunteed to be called if the worker errors. If you opened a file for some reason in before_invoke then you should close the file in a before_ensure or after_ensure based on your needs.
  • Loading branch information...
commit 1e46592f4ac7a6adf44c0380a5ed4209ce84f183 1 parent 42274f0
jrwest authored
Showing with 17 additions and 2 deletions.
  1. +9 −2 lib/job/callbacks.rb
  2. +8 −0 spec/lib/job/callbacks_spec.rb
View
11 lib/job/callbacks.rb
@@ -1,7 +1,7 @@
module Job::Callbacks
def self.included(base)
- befores = %w/invoke rescue/
- afters = %w/init invoke rescue/
+ befores = %w/invoke rescue ensure/
+ afters = %w/init invoke rescue ensure/
cb_points = {:before => befores, :after => afters}
base.extend(ClassMethods)
@@ -9,6 +9,7 @@ def self.included(base)
base.alias_method_chain :initialize_worker, :callbacks
base.alias_method_chain :invoke_worker, :callbacks
base.alias_method_chain :rescue_worker, :callbacks
+ base.alias_method_chain :ensure_worker, :callbacks
end
def initialize_worker_with_callbacks
@@ -30,6 +31,12 @@ def rescue_worker_with_callbacks(exception)
call_after_rescues
end
+ def ensure_worker_with_callbacks
+ call_before_ensures
+ ensure_worker_without_callbacks
+ call_after_ensures
+ end
+
private
def call_simple_worker_before_magic
View
8 spec/lib/job/callbacks_spec.rb
@@ -55,6 +55,14 @@ class ExampleWorker; end
end
it_should_behave_like "Any CB Point"
end
+ describe "before_ensure" do
+ let(:callback_point) { :before_ensure }
+ it_should_behave_like "Any CB Point"
+ end
+ describe "after_ensure" do
+ let(:callback_point) { :after_ensure }
+ it_should_behave_like "Any CB Point"
+ end
describe "magic hooks (worker hooks)" do
before(:each) do
some_instance.initialize_worker
Please sign in to comment.
Something went wrong with that request. Please try again.