resque-batched-job 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,26 +21,6 @@ module Resque
|
|
|
21
21
|
def batch(id)
|
|
22
22
|
"batch:#{id}"
|
|
23
23
|
end
|
|
24
|
-
|
|
25
|
-
#
|
|
26
|
-
# Use this method to configure batch locking. By default, all jobs lock
|
|
27
|
-
# the batch they belong to. Use
|
|
28
|
-
# def lock_batch=(true_or_false)
|
|
29
|
-
# @@_lock = true_or_false
|
|
30
|
-
# end
|
|
31
|
-
|
|
32
|
-
#
|
|
33
|
-
# Create the batch lock. This ensures only one worker is processing a
|
|
34
|
-
# batch at any given time.
|
|
35
|
-
def lock(id)
|
|
36
|
-
"lock:batch:#{id}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
def lock!(id)
|
|
42
|
-
redis.setnx(lock(id))
|
|
43
|
-
end
|
|
44
24
|
|
|
45
25
|
#
|
|
46
26
|
# Batch the job. The first argument of a batched job, is the batch id.
|
|
@@ -61,16 +41,12 @@ module Resque
|
|
|
61
41
|
|
|
62
42
|
#
|
|
63
43
|
# After every job, no matter in the event of success or failure, we need
|
|
64
|
-
# to remove the job from the batch set.
|
|
65
|
-
# the lock key after each job. This will allow others jobs in a batch to
|
|
66
|
-
# be processed.
|
|
44
|
+
# to remove the job from the batch set.
|
|
67
45
|
def around_perform_amend_batch(id, *args)
|
|
68
|
-
return unless redis.setnx(lock(id), true)
|
|
69
46
|
begin
|
|
70
47
|
yield
|
|
71
48
|
ensure
|
|
72
49
|
redis.srem(batch(id), "#{encode(args)}")
|
|
73
|
-
redis.del(lock(id))
|
|
74
50
|
end
|
|
75
51
|
end
|
|
76
52
|
|
data/test/test_batched_job.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '../lib')
|
|
2
|
-
|
|
3
1
|
require 'rubygems'
|
|
4
2
|
require 'test/unit'
|
|
5
3
|
require 'resque'
|
|
4
|
+
|
|
5
|
+
$:.unshift(File.dirname(__FILE__) + '../lib')
|
|
6
|
+
|
|
6
7
|
require 'resque/plugins/batched_job'
|
|
7
8
|
|
|
8
9
|
class Job
|
|
@@ -12,12 +13,12 @@ class Job
|
|
|
12
13
|
@queue = :test
|
|
13
14
|
|
|
14
15
|
def self.perform(batch_id)
|
|
15
|
-
$stdout.puts "perform
|
|
16
|
+
$stdout.puts "perform batch[#{batch_id}]"
|
|
16
17
|
sleep 1
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def self.after_batch_hook(batch_id)
|
|
20
|
-
$stdout.puts "
|
|
21
|
+
$stdout.puts "after_bactch [#{batch_id}]"
|
|
21
22
|
sleep 1
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -36,7 +37,7 @@ class BatchedJobTest < Test::Unit::TestCase
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def test_batched_job
|
|
39
|
-
5.times { Resque.enqueue(Job, 1) }
|
|
40
|
+
5.times { Resque.enqueue(Job, 1, "arg#{rand(100)}") }
|
|
40
41
|
worker = Resque::Worker.new(:test)
|
|
41
42
|
worker.work
|
|
42
43
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 4
|
|
9
|
+
version: 0.1.4
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Daniel Johnston
|
|
@@ -32,8 +32,8 @@ dependencies:
|
|
|
32
32
|
version: 1.10.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
version_requirements: *id001
|
|
35
|
-
description: " Resque plugin
|
|
36
|
-
|
|
35
|
+
description: " Resque plugin for batching jobs. When a batch/group of jobs are complete, \n\
|
|
36
|
+
additional work can be performed usings batch hooks.\n"
|
|
37
37
|
email: dan@dj-agiledev.com
|
|
38
38
|
executables: []
|
|
39
39
|
|