canvas-jobs 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad93c34959f9fd5742ab07582c6708cb6701febe
4
- data.tar.gz: e10385f439aa7f34293c545b6bb3a094a645b0ba
3
+ metadata.gz: ad6300227d1380ed20717f92ebd1d628295685b4
4
+ data.tar.gz: 6b18acd99fb06b30edcb80ed90fbf117f5f3eab6
5
5
  SHA512:
6
- metadata.gz: b02c7e200b1e9b4e337cdecee326cc49652299bea939fa74fba97ac62c010b2a97d3289a5db048349a4ad09d992070f368a9785203bf15755565394e81d7d579
7
- data.tar.gz: d24c55eef5e03eed2398062c9e16fb850b8cec4344011aeeebc64ffc8bca400b4f444b8a7b3fc7477591f8a97fd01596dffd7072671f3e054d4c9e04bc746df7
6
+ metadata.gz: e902946c32dcb6ea0be687066837cc94254714df18e9e7a562e2308d563a24382b300990ef1f59d4c9d1c1b6145984a2c7d0d72d7e967ef4e72516a8bc78a0c6
7
+ data.tar.gz: ebf19119b6be32e917de452611ca1f73b555cfb76616a4caa6c09f0db709afe7059ba2bb26e1beb2ac1819d966be41869f0d8a9bc75931a7910c1d69997b582b
@@ -219,12 +219,14 @@ module Delayed
219
219
 
220
220
  # Moved into its own method so that new_relic can trace it.
221
221
  def invoke_job
222
- Delayed::Job.in_delayed_job = true
223
- begin
224
- payload_object.perform
225
- ensure
226
- Delayed::Job.in_delayed_job = false
227
- ::ActiveRecord::Base.clear_active_connections! unless Rails.env.test?
222
+ Delayed::Worker.lifecycle.run_callbacks(:invoke_job, self) do
223
+ Delayed::Job.in_delayed_job = true
224
+ begin
225
+ payload_object.perform
226
+ ensure
227
+ Delayed::Job.in_delayed_job = false
228
+ ::ActiveRecord::Base.clear_active_connections! unless Rails.env.test?
229
+ end
228
230
  end
229
231
  end
230
232
 
@@ -6,6 +6,7 @@ module Delayed
6
6
  :perform => [:worker, :job],
7
7
  :pop => [:worker],
8
8
  :exceptional_exit => [:worker, :exception],
9
+ :invoke_job => [:job],
9
10
  }
10
11
 
11
12
  def initialize
@@ -14,6 +15,7 @@ module Delayed
14
15
 
15
16
  def reset!
16
17
  @callbacks = EVENTS.keys.inject({}) { |hash, e| hash[e] = Callback.new; hash }
18
+ Delayed::Worker.plugins.each { |plugin| plugin.reset! }
17
19
  end
18
20
 
19
21
  def before(event, &block)
@@ -0,0 +1,22 @@
1
+ require 'active_support/core_ext/class/attribute'
2
+
3
+ module Delayed
4
+ class Plugin
5
+ class_attribute :callback_block
6
+
7
+ def self.callbacks(&block)
8
+ self.callback_block = block
9
+ end
10
+
11
+ def self.inject!
12
+ unless @injected
13
+ self.callback_block.call(Delayed::Worker.lifecycle) if self.callback_block
14
+ end
15
+ @injected = true
16
+ end
17
+
18
+ def self.reset!
19
+ @injected = false
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Delayed
2
- VERSION = "0.9.9"
2
+ VERSION = "0.9.10"
3
3
  end
@@ -3,6 +3,7 @@ module Delayed
3
3
  class TimeoutError < RuntimeError; end
4
4
 
5
5
  require 'tmpdir'
6
+ require 'set'
6
7
 
7
8
  class Worker
8
9
  attr_reader :config, :queue, :min_priority, :max_priority
@@ -20,6 +21,9 @@ class Worker
20
21
  end
21
22
  cattr_reader :on_max_failures
22
23
 
24
+ cattr_accessor :plugins
25
+ self.plugins = Set.new
26
+
23
27
  def self.lifecycle
24
28
  @lifecycle ||= Delayed::Lifecycle.new
25
29
  end
@@ -47,6 +51,8 @@ class Worker
47
51
  end
48
52
  end
49
53
  end
54
+
55
+ plugins.each { |plugin| plugin.inject! }
50
56
  end
51
57
 
52
58
  def name=(name)
@@ -29,6 +29,7 @@ require 'delayed/lifecycle'
29
29
  require 'delayed/message_sending'
30
30
  require 'delayed/performable_method'
31
31
  require 'delayed/periodic'
32
+ require 'delayed/plugin'
32
33
  require 'delayed/pool'
33
34
  require 'delayed/worker'
34
35
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.8)
4
+ canvas-jobs (0.9.9)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.8)
4
+ canvas-jobs (0.9.9)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.8)
4
+ canvas-jobs (0.9.9)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.8)
4
+ canvas-jobs (0.9.9)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -130,6 +130,7 @@ GEM
130
130
  actionpack (>= 4.0)
131
131
  activesupport (>= 4.0)
132
132
  sprockets (~> 2.8)
133
+ syck (1.0.4)
133
134
  test_after_commit (0.3.0)
134
135
  activerecord (>= 3.2)
135
136
  thor (0.19.1)
@@ -152,6 +153,7 @@ DEPENDENCIES
152
153
  rails (~> 4.2.0.beta2)
153
154
  rake
154
155
  rspec
156
+ syck
155
157
  test_after_commit
156
158
  timecop
157
159
  wwtd
@@ -288,4 +288,27 @@ shared_examples_for 'Delayed::Worker' do
288
288
  worker.queue.should == queue_name
289
289
  end
290
290
  end
291
+
292
+ context "plugins" do
293
+ class TestPlugin < ::Delayed::Plugin
294
+ cattr_accessor :runs
295
+ self.runs = 0
296
+ callbacks do |lifecycle|
297
+ lifecycle.around(:invoke_job) do |job, *args, &block|
298
+ TestPlugin.runs += 1
299
+ block.call(job, *args)
300
+ end
301
+ end
302
+ end
303
+
304
+ it "should create and call the plugin callbacks" do
305
+ TestPlugin.runs = 0
306
+ Delayed::Worker.plugins << TestPlugin
307
+ job_create
308
+ @worker = Delayed::Worker.new(:quiet => true)
309
+ @worker.run
310
+ expect(TestPlugin.runs).to eq(1)
311
+ expect(SimpleJob.runs).to eq(1)
312
+ end
313
+ end
291
314
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-24 00:00:00.000000000 Z
12
+ date: 2014-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: after_transaction_commit
@@ -254,6 +254,7 @@ files:
254
254
  - lib/delayed/message_sending.rb
255
255
  - lib/delayed/performable_method.rb
256
256
  - lib/delayed/periodic.rb
257
+ - lib/delayed/plugin.rb
257
258
  - lib/delayed/pool.rb
258
259
  - lib/delayed/settings.rb
259
260
  - lib/delayed/testing.rb
@@ -300,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
301
  version: '0'
301
302
  requirements: []
302
303
  rubyforge_project:
303
- rubygems_version: 2.2.2
304
+ rubygems_version: 2.4.4
304
305
  signing_key:
305
306
  specification_version: 4
306
307
  summary: Instructure-maintained fork of delayed_job
@@ -325,3 +326,4 @@ test_files:
325
326
  - spec/shared/worker.rb
326
327
  - spec/shared_jobs_specs.rb
327
328
  - spec/spec_helper.rb
329
+ has_rdoc: