resque-batched-job 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +19 -23
- data/Rakefile +1 -1
- data/lib/resque/plugins/batched_job/version.rb +1 -1
- data/lib/resque/plugins/batched_job.rb +25 -1
- metadata +5 -5
data/README.markdown
CHANGED
@@ -3,31 +3,27 @@ Resque Batched Job
|
|
3
3
|
|
4
4
|
A [Resque](http://github.com/defunkt/resque) plugin. Requires Resque 1.10.0
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
* Define a complete batch
|
6
|
+
This plugin adds the ability to batch jobs and run additional hooks after the last job in a batch is performed. Using the 'after_enqueue' hook, the jobs
|
7
|
+
arguments are stored in a Redis set identified by the batch id provided. By default, the batch keys look like 'batch:<id>'. After each job is performed, its arguments are removed from the set. If the last job performed happens to be the last in a set, additional hooks are executed. These hooks are prefixed with 'after_batch'.
|
9
8
|
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
gem install resque-batched-job
|
13
|
+
|
10
14
|
Example
|
11
15
|
-------
|
16
|
+
|
17
|
+
module Job
|
18
|
+
|
19
|
+
extend Resque::Plugins::BatchedJob
|
20
|
+
|
21
|
+
def self.perform(id, *args)
|
22
|
+
prime(id, args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.after_batch_heavy_lifting(id, *args)
|
26
|
+
heavy_lifting(id)
|
27
|
+
end
|
12
28
|
|
13
|
-
class Job
|
14
|
-
|
15
|
-
extend Resque::Plugins::BatchedJob
|
16
|
-
|
17
|
-
@queue = :example
|
18
|
-
|
19
|
-
def self.before_perform_clean_up(place, name)
|
20
|
-
puts "#{name} straightening up desk"
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.perform(place, name)
|
24
|
-
puts "#{name} leaving the #{place}"
|
25
|
-
sleep 1
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.after_batch_turn_lights_out(place, name)
|
29
|
-
puts "#{name} turing the lights out in the #{place}."
|
30
|
-
sleep 1
|
31
|
-
end
|
32
|
-
|
33
29
|
end
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ task :publish => :build do
|
|
17
17
|
require 'lib/resque/plugins/batched_job/version'
|
18
18
|
sh "gem push resque-batched-job-#{Resque::Plugins::BatchedJob::VERSION}.gem"
|
19
19
|
sh "git tag v#{Resque::Plugins::BatchedJob::VERSION}"
|
20
|
-
sh "git
|
20
|
+
sh "git push origin v#{Resque::Plugins::BatchedJob::VERSION}"
|
21
21
|
sh "git push origin master"
|
22
22
|
end
|
23
23
|
|
@@ -21,6 +21,26 @@ 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
|
24
44
|
|
25
45
|
#
|
26
46
|
# Batch the job. The first argument of a batched job, is the batch id.
|
@@ -41,12 +61,16 @@ module Resque
|
|
41
61
|
|
42
62
|
#
|
43
63
|
# After every job, no matter in the event of success or failure, we need
|
44
|
-
# to remove the job from the batch set.
|
64
|
+
# to remove the job from the batch set. If batch locking is enabled, remove
|
65
|
+
# the lock key after each job. This will allow others jobs in a batch to
|
66
|
+
# be processed.
|
45
67
|
def around_perform_amend_batch(id, *args)
|
68
|
+
return unless redis.setnx(lock(id), true)
|
46
69
|
begin
|
47
70
|
yield
|
48
71
|
ensure
|
49
72
|
redis.srem(batch(id), "#{encode(args)}")
|
73
|
+
redis.del(lock(id))
|
50
74
|
end
|
51
75
|
end
|
52
76
|
|
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
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Johnston
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11
|
17
|
+
date: 2010-12-11 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -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 that understands individual jobs can belong to something bigger \n\
|
36
|
+
than themselves.\n"
|
37
37
|
email: dan@dj-agiledev.com
|
38
38
|
executables: []
|
39
39
|
|