quebert 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/quebert/job.rb CHANGED
@@ -40,6 +40,7 @@ module Quebert
40
40
  @delay = DEFAULT_JOB_DELAY
41
41
  @ttr = DEFAULT_JOB_TTR
42
42
  @args = args.dup.freeze
43
+ yield self if block_given?
43
44
  self
44
45
  end
45
46
 
@@ -55,14 +56,18 @@ module Quebert
55
56
  Quebert::Timeout.timeout(@ttr, Job::Timeout){ perform(*args) }
56
57
  end
57
58
 
58
- def enqueue
59
+ # Accepts arguments that override the job options and enqueu this stuff.
60
+ def enqueue(opts={})
61
+ opts.each { |opt, val| self.send("#{opt}=", val) }
59
62
  self.class.backend.put self, @priority, @delay, @ttr + QUEBERT_TTR_BUFFER
60
63
  end
61
64
 
65
+ # Serialize the job into a JSON string that we can put on the beandstalkd queue.
62
66
  def to_json
63
67
  JSON.generate(Serializer::Job.serialize(self))
64
68
  end
65
69
 
70
+ # Read a JSON string and convert into a hash that Ruby can deal with.
66
71
  def self.from_json(json)
67
72
  if hash = JSON.parse(json) and not hash.empty?
68
73
  Serializer::Job.deserialize(hash)
@@ -1,3 +1,3 @@
1
1
  module Quebert
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/spec/job_spec.rb CHANGED
@@ -6,6 +6,10 @@ describe Quebert::Job do
6
6
  Adder.backend = @q = Quebert::Backend::InProcess.new
7
7
  end
8
8
 
9
+ it "shoud initialize with block" do
10
+ Adder.new(1,2,3){|a| a.priority = 8080 }.priority.should == 8080
11
+ end
12
+
9
13
  it "should perform!" do
10
14
  Adder.new(1,2,3).perform!.should eql(6)
11
15
  end
@@ -71,6 +75,25 @@ describe Quebert::Job do
71
75
  }.should change(@q, :size).by(1)
72
76
  end
73
77
 
78
+ context "#enqueue options" do
79
+ let(:job){ Adder.new(1,2,3) }
80
+
81
+ it "should enqueue with pri" do
82
+ job.should_receive(:pri=).with(100)
83
+ job.enqueue(:pri => 100)
84
+ end
85
+
86
+ it "should enqueue with ttr" do
87
+ job.should_receive(:ttr=).with(90)
88
+ job.enqueue(:ttr => 90)
89
+ end
90
+
91
+ it "should enqueue with delay" do
92
+ job.should_receive(:delay=).with(80)
93
+ job.enqueue(:delay => 80)
94
+ end
95
+ end
96
+
74
97
  context "beanstalk backend" do
75
98
  before(:all) do
76
99
  Quebert.serializers.register 'ActiveRecord::Base', Serializer::ActiveRecord
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quebert
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brad Gessler
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2013-04-27 00:00:00 Z
20
+ date: 2013-05-09 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json