quebert 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bda9cb5709ea354e0ccb9822af9866fc9074795
4
- data.tar.gz: 45923c3de44f7d15397732d30448931540847f50
3
+ metadata.gz: 016b1258661f9dbac4d3d3dd2c53b482d0d7c80f
4
+ data.tar.gz: ec28cd67f06d964274b67bccfb3605cf7fc49326
5
5
  SHA512:
6
- metadata.gz: 41ad3f71924915e1ce6341b45cd8f079925dc2cfba0859bd2282d6eabf448a192841065663d0871c83830553f7b2eeb5029d6f1f5ec0f0be5c8a0a4d830dfea1
7
- data.tar.gz: 466dd771292f13cae5fc7f876c23dea8bb9935dcc396a4d0fbe0e5e537f13024e6e68af71864f61e154a68f6145ee31d8e9364b90463f2dd46bcbfbb2a65e398
6
+ metadata.gz: caf6fd9be90fbe25b6890864c031dce330cd30ffa14672ec25d02d04e46a08dd155081210e64bcb38f3383ead08ad588ece9c5a1be69a7b31c1a2c37ea83f191
7
+ data.tar.gz: b8140800516ec10fd31e6fe12a36e5db6b123be6e2942b5ef111f8dd0c05b7c44cf652daeb99c94c5e2e57575c403e5975fb24da51038b2cb779508d42bb5348
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Quebert
2
2
 
3
- [![Build Status](https://travis-ci.org/polleverywhere/quebert.png?branch=master)](https://travis-ci.org/polleverywhere/quebert)
3
+ [![Build Status](https://travis-ci.org/polleverywhere/quebert.png?branch=master)](https://travis-ci.org/polleverywhere/quebert) [![Code Climate](https://codeclimate.com/repos/555266fc6956805b9e0033b5/badges/008e51483e8e268f21db/gpa.svg)](https://codeclimate.com/repos/555266fc6956805b9e0033b5/feed)
4
4
 
5
5
  async_observer is great, but is dated and doesn't really support running jobs outside of the async_send idiom. Quebert is an attempt to mix how jobs are run in other popular worker queue frameworks, like resque and dj, with async_observer so that you can have it both ways.
6
6
 
@@ -15,24 +15,15 @@ module Quebert
15
15
  def initialize(beanstalk_job)
16
16
  @beanstalk_job = beanstalk_job
17
17
  @job = Job.from_json(beanstalk_job.body)
18
- rescue Job::Delete
19
- beanstalk_job.delete
20
- job_log "Deleted on initialization", :error
21
- rescue Job::Release
22
- beanstalk_job.release job.priority, job.delay
23
- job_log "Released on initialization with priority: #{job.priority} and delay: #{job.delay}", :error
24
- rescue Job::Bury
25
- beanstalk_job.bury
26
- job_log "Buried on initialization", :error
27
18
  rescue => e
28
19
  beanstalk_job.bury
29
- job_log "Error caught on initialization. #{e.inspect}", :error
20
+ logger.error "Error caught on initialization. #{e.inspect}"
30
21
  raise
31
22
  end
32
23
 
33
24
  def perform
34
- job_log "Performing with args #{job.args.inspect}"
35
- job_log "Beanstalk Job Stats: #{beanstalk_job.stats.inspect}"
25
+ logger.error(job) { "Performing with args #{job.args.inspect}" }
26
+ logger.error(job) { "Beanstalk Job Stats: #{beanstalk_job.stats.inspect}" }
36
27
 
37
28
  result = false
38
29
  time = Benchmark.realtime do
@@ -40,33 +31,33 @@ module Quebert
40
31
  beanstalk_job.delete
41
32
  end
42
33
 
43
- job_log "Completed in #{(time*1000*1000).to_i/1000.to_f} ms\n"
34
+ logger.error(job) { "Completed in #{(time*1000*1000).to_i/1000.to_f} ms\n" }
44
35
  result
45
36
  rescue Job::Delete
46
- job_log "Deleting job", :error
37
+ logger.info(job) { "Deleting job" }
47
38
  beanstalk_job.delete
48
- job_log "Job deleted", :error
39
+ logger.info(job) { "Job deleted" }
49
40
  rescue Job::Release
50
- job_log "Releasing with priority: #{job.priority} and delay: #{job.delay}", :error
41
+ logger.info(job) { "Releasing with priority: #{job.priority} and delay: #{job.delay}" }
51
42
  beanstalk_job.release :pri => job.priority, :delay => job.delay
52
- job_log "Job released", :error
43
+ logger.info(job) { "Job released" }
53
44
  rescue Job::Bury
54
- job_log "Burrying job", :error
45
+ logger.info(job) { "Burrying job" }
55
46
  beanstalk_job.bury
56
- job_log "Job burried", :error
47
+ logger.info(job) { "Job buried" }
57
48
  rescue Job::Timeout => e
58
- job_log "Job timed out. Retrying with delay. #{e.inspect} #{e.backtrace.join("\n")}", :error
49
+ logger.info(job) { "Job timed out. Retrying with delay. #{e.inspect} #{e.backtrace.join("\n")}" }
59
50
  retry_with_delay
60
51
  raise
61
52
  rescue Job::Retry
62
53
  # The difference between the Retry and Timeout class is that
63
- # Retry does not job_log an exception where as Timeout does
64
- job_log "Manually retrying with delay"
54
+ # Retry does not logger.error(job) { an exception where as Timeout does }
55
+ logger.info(job) { "Manually retrying with delay" }
65
56
  retry_with_delay
66
57
  rescue => e
67
- job_log "Error caught on perform. Burying job. #{e.inspect} #{e.backtrace.join("\n")}", :error
58
+ logger.error(job) { "Error caught on perform. Burying job. #{e.inspect} #{e.backtrace.join("\n")}" }
68
59
  beanstalk_job.bury
69
- job_log "Job buried", :error
60
+ logger.error(job) { "Job buried" }
70
61
  raise
71
62
  end
72
63
 
@@ -75,28 +66,19 @@ module Quebert
75
66
  delay = TIMEOUT_RETRY_DELAY_SEED + TIMEOUT_RETRY_GROWTH_RATE**beanstalk_job.stats["releases"].to_i
76
67
 
77
68
  if delay > MAX_TIMEOUT_RETRY_DELAY
78
- job_log "Max retry delay exceeded. Burrying job"
69
+ logger.error(job) { "Max retry delay exceeded. Burrying job" }
79
70
  beanstalk_job.bury
80
- job_log "Job burried"
71
+ logger.error(job) { "Job buried" }
81
72
  else
82
- job_log "TTR exceeded. Releasing with priority: #{job.priority} and delay: #{delay}"
73
+ logger.error(job) { "TTR exceeded. Releasing with priority: #{job.priority} and delay: #{delay}" }
83
74
  beanstalk_job.release :pri => job.priority, :delay => delay
84
- job_log "Job released"
75
+ logger.error(job) { "Job released" }
85
76
  end
86
77
  rescue ::Beaneater::NotFoundError
87
- job_log "Job ran longer than allowed. Beanstalk already deleted it!!!!", :error
78
+ logger.error(job) { "Job ran longer than allowed. Beanstalk already deleted it!!!!" }
88
79
  # Sometimes the timer doesn't behave correctly and this job actually runs longer than
89
80
  # allowed. At that point the beanstalk job no longer exists anymore. Lets let it go and don't blow up.
90
81
  end
91
-
92
- def job_log(message, level=:info)
93
- # Have the job write to the log file so that we catch the details of the job
94
- if job
95
- job.send(:log, message, level)
96
- else
97
- Quebert.logger.send(level, message)
98
- end
99
- end
100
82
  end
101
83
  end
102
84
  end
data/lib/quebert/job.rb CHANGED
@@ -23,7 +23,6 @@ module Quebert
23
23
 
24
24
  # Exceptions are used for signaling job status... ewww. Yank this out and
25
25
  # replace with a more well thought out controller.
26
- NotImplemented = Class.new(StandardError)
27
26
  Action = Class.new(Exception)
28
27
  Bury = Class.new(Action)
29
28
  Delete = Class.new(Action)
@@ -41,7 +40,7 @@ module Quebert
41
40
  end
42
41
 
43
42
  def perform(*args)
44
- raise NotImplemented
43
+ raise NotImplementedError
45
44
  end
46
45
 
47
46
  # Runs the perform method that somebody else should be implementing
@@ -1,13 +1,8 @@
1
1
  module Quebert
2
2
  module Logging
3
- protected
3
+ private
4
4
  def logger
5
- @logger ||= Quebert.logger
6
- end
7
-
8
- # Making logging jobs a tiny bit easier..
9
- def log(message, level=:info)
10
- logger.send(level, "[##{self.object_id} #{self.class.name}] : #{message}")
5
+ Quebert.logger
11
6
  end
12
7
  end
13
8
  end
@@ -1,3 +1,3 @@
1
1
  module Quebert
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
data/spec/job_spec.rb CHANGED
@@ -21,7 +21,7 @@ describe Quebert::Job do
21
21
  it "should raise not implemented on base job" do
22
22
  lambda {
23
23
  Job.new.perform
24
- }.should raise_exception(Quebert::Job::NotImplemented)
24
+ }.should raise_exception(NotImplementedError)
25
25
  end
26
26
 
27
27
  it "should convert job to and from JSON" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quebert
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
@@ -149,3 +149,4 @@ test_files:
149
149
  - spec/support/jobs.rb
150
150
  - spec/support_spec.rb
151
151
  - spec/worker_spec.rb
152
+ has_rdoc: