resque-batched-job 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +24 -20
- data/lib/resque/plugins/batched_job.rb +18 -26
- data/lib/resque/plugins/batched_job/version.rb +1 -1
- metadata +5 -5
data/README.markdown
CHANGED
@@ -1,28 +1,32 @@
|
|
1
|
-
Resque Batched Job
|
2
|
-
==================
|
1
|
+
# Resque Batched Job
|
3
2
|
|
4
3
|
A [Resque](http://github.com/defunkt/resque) plugin. Requires Resque 1.10.0
|
5
4
|
|
6
|
-
This plugin adds the ability to batch jobs and run additional hooks after the
|
7
|
-
|
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 jobs
|
7
|
+
arguments are stored in a Redis set identified by the batch id provided.
|
8
|
+
By default, the batch keys look like 'batch:<id>'. After each job is performed,
|
9
|
+
its arguments are removed from the set. If the last job performed happens to be
|
10
|
+
the last in a set, additional hooks are executed. These hooks are prefixed with
|
11
|
+
'after_batch'.
|
8
12
|
|
13
|
+
## Installation
|
9
14
|
|
10
|
-
|
11
|
-
------------
|
12
|
-
gem install resque-batched-job
|
13
|
-
|
14
|
-
Example
|
15
|
-
-------
|
16
|
-
|
17
|
-
module Job
|
18
|
-
extend Resque::Plugins::BatchedJob
|
15
|
+
$ gem install resque-batched-job
|
19
16
|
|
20
|
-
|
21
|
-
prime(id, args)
|
22
|
-
end
|
17
|
+
## Example
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
```ruby
|
20
|
+
module Job
|
21
|
+
extend Resque::Plugins::BatchedJob
|
27
22
|
|
28
|
-
|
23
|
+
def self.perform(id, *args)
|
24
|
+
prime(id, args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.after_batch_heavy_lifting(id, *args)
|
28
|
+
heavy_lifting(id)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
```
|
@@ -1,33 +1,30 @@
|
|
1
1
|
module Resque
|
2
|
-
|
2
|
+
|
3
3
|
module Plugin
|
4
|
-
|
5
|
-
#
|
4
|
+
|
6
5
|
# This hook is really the meaning of our adventure.
|
7
6
|
def after_batch_hooks(job)
|
8
7
|
job.methods.grep(/^after_batch/).sort
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
module Plugins
|
14
|
-
|
13
|
+
|
15
14
|
module BatchedJob
|
16
|
-
|
15
|
+
|
17
16
|
include Resque::Helpers
|
18
17
|
|
19
|
-
#
|
20
18
|
# Helper method used to generate the batch key.
|
21
19
|
def batch(id)
|
22
20
|
"batch:#{id}"
|
23
21
|
end
|
24
22
|
|
25
|
-
#
|
26
23
|
# Batch the job. The first argument of a batched job, is the batch id.
|
27
24
|
def after_enqueue_batch(id, *args)
|
28
|
-
redis.sadd(batch(id), encode(
|
25
|
+
redis.sadd(batch(id), encode(:class => self, :args => args))
|
29
26
|
end
|
30
|
-
|
27
|
+
|
31
28
|
=begin
|
32
29
|
TODO: Determine if it's necessary to double check the jobs existance
|
33
30
|
before performing it. If so, do what?
|
@@ -39,19 +36,15 @@ module Resque
|
|
39
36
|
end
|
40
37
|
=end
|
41
38
|
|
42
|
-
#
|
43
|
-
# After every job, no matter in the event of success or failure, we need
|
39
|
+
# After every job, no matter in the event of success or failure, we need
|
44
40
|
# to remove the job from the batch set.
|
45
41
|
def around_perform_amend_batch(id, *args)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
redis.srem(batch(id), "#{encode(args.insert(0, self.name))}")
|
50
|
-
end
|
42
|
+
yield
|
43
|
+
ensure
|
44
|
+
redis.srem(batch(id), "#{encode(:class => self, :args => args)}")
|
51
45
|
end
|
52
46
|
|
53
|
-
#
|
54
|
-
# After each job is performed, check to see if the job is the last of
|
47
|
+
# After each job is performed, check to see if the job is the last of
|
55
48
|
# the given batch. If so, run after_batch hooks.
|
56
49
|
def after_perform_batch(id, *args)
|
57
50
|
if batch_complete?(id)
|
@@ -61,18 +54,17 @@ module Resque
|
|
61
54
|
end
|
62
55
|
end
|
63
56
|
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Checks to see if the batch key exists. If the key does exist, is the
|
57
|
+
|
58
|
+
# Checks to see if the batch key exists. If the key does exist, is the
|
67
59
|
# set empty? The Redis srem command deletes the key when the last item
|
68
60
|
# of a set is removed. Ah, go ahead and check the size.
|
69
61
|
def batch_complete?(id)
|
70
62
|
redis.scard(batch(id)) == 0
|
71
63
|
end
|
72
64
|
alias :batch_exist? :batch_complete? # => are they?
|
73
|
-
|
65
|
+
|
74
66
|
end
|
75
|
-
|
67
|
+
|
76
68
|
end
|
77
|
-
|
69
|
+
|
78
70
|
end
|
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.2.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
|
+
date: 2011-12-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
16
|
-
requirement: &
|
16
|
+
requirement: &70189643729620 !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: *70189643729620
|
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
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.8.
|
59
|
+
rubygems_version: 1.8.10
|
60
60
|
signing_key:
|
61
61
|
specification_version: 3
|
62
62
|
summary: Resque plugin
|