resque-batched-job 0.2.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,13 @@
|
|
1
1
|
# Resque Batched Job
|
2
2
|
|
3
|
-
A [Resque](http://github.com/defunkt/resque) plugin. Requires Resque 1.10.0
|
3
|
+
A [Resque](http://github.com/defunkt/resque) plugin. Requires Resque >= 1.10.0
|
4
4
|
|
5
5
|
This plugin adds the ability to batch jobs and run additional hooks after the
|
6
|
-
last job in a batch is performed. Using the 'after_enqueue' hook, the
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'after_batch'.
|
6
|
+
last job in a batch is performed. Using the '*after_enqueue*' hook, the job
|
7
|
+
is encoded and stored in a Redis List identified by the batch id provided. By default,
|
8
|
+
the batch keys look like '*batch:#{id}*'. After each job is performed, it's removed
|
9
|
+
from the batch list. If the last job performed happens to be the last in the list,
|
10
|
+
additional hooks are executed. These hooks are prefixed with '*after_batch*'.
|
12
11
|
|
13
12
|
## Installation
|
14
13
|
|
@@ -22,31 +22,14 @@ module Resque
|
|
22
22
|
|
23
23
|
# Batch the job. The first argument of a batched job, is the batch id.
|
24
24
|
def after_enqueue_batch(id, *args)
|
25
|
-
redis.
|
25
|
+
redis.rpush(batch(id), encode(:class => self, :args => args))
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def before_perform_audit_batch(id, *args)
|
33
|
-
unless redis.sismember(batch(id), "#{encode(args)}")
|
34
|
-
raise Resque::Job::DontPerform.new("#{args} are not a member of #{batch(id)}")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
=end
|
38
|
-
|
39
|
-
# After every job, no matter in the event of success or failure, we need
|
40
|
-
# to remove the job from the batch set.
|
41
|
-
def around_perform_amend_batch(id, *args)
|
42
|
-
yield
|
43
|
-
ensure
|
44
|
-
redis.srem(batch(id), "#{encode(:class => self, :args => args)}")
|
45
|
-
end
|
46
|
-
|
47
|
-
# After each job is performed, check to see if the job is the last of
|
48
|
-
# the given batch. If so, run after_batch hooks.
|
28
|
+
# After the job is performed, remove it from the batched job list. If the
|
29
|
+
# current job is the last in the batch to be performed, invoke the after_batch
|
30
|
+
# hooks.
|
49
31
|
def after_perform_batch(id, *args)
|
32
|
+
redis.lrem(batch(id), 1, encode(:class => self, :args => args))
|
50
33
|
if batch_complete?(id)
|
51
34
|
after_batch_hooks = Resque::Plugin.after_batch_hooks(self)
|
52
35
|
after_batch_hooks.each do |hook|
|
@@ -55,13 +38,15 @@ module Resque
|
|
55
38
|
end
|
56
39
|
end
|
57
40
|
|
58
|
-
# Checks
|
59
|
-
#
|
60
|
-
# of a set is removed. Ah, go ahead and check the size.
|
41
|
+
# Checks the size of the batched job list and returns true if the list is
|
42
|
+
# empty or if the key does not exist.
|
61
43
|
def batch_complete?(id)
|
62
|
-
redis.
|
44
|
+
redis.llen(batch(id)) == 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def batch_exist?(id)
|
48
|
+
redis.exists(batch(id))
|
63
49
|
end
|
64
|
-
alias :batch_exist? :batch_complete? # => are they?
|
65
50
|
|
66
51
|
end
|
67
52
|
|
data/test/test_batched_job.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-batched-job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
16
|
-
requirement: &
|
16
|
+
requirement: &70335551372100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.10.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70335551372100
|
25
25
|
description: ! " Resque plugin for batching jobs. When a batch/group of jobs are
|
26
26
|
complete, \nadditional work can be performed usings batch hooks.\n"
|
27
27
|
email: dan@dj-agiledev.com
|
@@ -31,7 +31,7 @@ extra_rdoc_files: []
|
|
31
31
|
files:
|
32
32
|
- LICENSE
|
33
33
|
- Rakefile
|
34
|
-
- README.
|
34
|
+
- README.md
|
35
35
|
- lib/resque/plugins/batched_job/version.rb
|
36
36
|
- lib/resque/plugins/batched_job.rb
|
37
37
|
- lib/resque-batched-job.rb
|