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 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'.
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
 
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module BatchedJob
4
- VERSION = '0.2.0'
4
+ VERSION = '0.6.0'
5
5
  end
6
6
  end
7
7
  end
@@ -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.sadd(batch(id), encode(:class => self, :args => args))
25
+ redis.rpush(batch(id), encode(:class => self, :args => args))
26
26
  end
27
27
 
28
- =begin
29
- TODO: Determine if it's necessary to double check the jobs existance
30
- before performing it. If so, do what?
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 to see if the batch key exists. If the key does exist, is the
59
- # set empty? The Redis srem command deletes the key when the last item
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.scard(batch(id)) == 0
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
 
@@ -42,7 +42,8 @@ class BatchedJobTest < Test::Unit::TestCase
42
42
  end
43
43
 
44
44
  def test_batch_size
45
- assert_equal(@cnt, redis.smembers(@batch).size)
45
+ # assert_equal(@cnt, redis.smembers(@batch).size)
46
+ assert_equal(@cnt, redis.llen(@batch))
46
47
  end
47
48
 
48
49
  def test_batch_hook
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.2.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-08 00:00:00.000000000Z
12
+ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
16
- requirement: &70189643729620 !ruby/object:Gem::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: *70189643729620
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.markdown
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