bushpig 0.1.6 → 0.1.7

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
  SHA256:
3
- metadata.gz: fc9bf6fabf6038b858a576750b32c827ad7095bca278de9bf1ae207258fd0c94
4
- data.tar.gz: 36be95562838f7868ccc13d76a5e4b77bc75220f18f19693e2fee001d710e21b
3
+ metadata.gz: 8d3c78ffe7777e02a7e1a7d4f4e1838ab47c80a5c9d0c1d61e6547c2b956065f
4
+ data.tar.gz: 64bc3d1e149b54e84a28e9f637b9495b7a6e9d7eec451304e310afd8bb473067
5
5
  SHA512:
6
- metadata.gz: cd5f62fdff7ace18ffac4ba7332d29f68a53debeda49f155fe784fe3ff14f2e70ef07cf26623087d134ae7c8e361cd8fe2536afb9f135d05716f850680ae255b
7
- data.tar.gz: f90b3ba40eb138d0e9a589d9d47f727218761f0a4cc8e022da0fce3395894cd50415f15349cf421a3995a56ecc08582bbe6a9b6b47ea79b1288bbce41e4c5fbe
6
+ metadata.gz: 9a1ca507019ef95f735f9b0558d1b4867fccec40a6fac62ced66f69d0ab57168a081af14dd661876221213c92e3c184393dabedefe8f706a1a12aa6354955bdd
7
+ data.tar.gz: 7148a4dabeff3df6575b455a08306342d9b488938593841882ed025e1f7a6fcbb35d22c5f29554a2269c78f3aa853808c84570d889aca8fadcac55ef5a362ec7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bushpig (0.1.6)
4
+ bushpig (0.1.7)
5
5
  connection_pool (~> 2.2)
6
6
  json (>= 1.8)
7
7
  redis (~> 3.3)
data/gemset.nix CHANGED
@@ -186,7 +186,7 @@
186
186
  path = ./.;
187
187
  type = "path";
188
188
  };
189
- version = "0.1.6";
189
+ version = "0.1.7";
190
190
  };
191
191
  coderay = {
192
192
  groups = ["default" "development"];
data/lib/bushpig.rb CHANGED
@@ -43,11 +43,11 @@ module Bushpig
43
43
  defined?(Bushpig::CLI)
44
44
  end
45
45
 
46
- def self.set_key(queue)
46
+ def self.queue_key(queue)
47
47
  "set:#{queue}"
48
48
  end
49
49
 
50
- def self.job_key(job_id)
51
- "job:#{job_id}"
50
+ def self.job_key(job_key)
51
+ "job:#{job_key}"
52
52
  end
53
53
  end
@@ -19,10 +19,10 @@ module Bushpig
19
19
  end
20
20
 
21
21
  def submit(queue, job, score: default_score, ttl: default_ttl)
22
- @callback.call(job)
22
+ modified = @callback.call(job)
23
23
  redis_pool.with do |conn|
24
- conn.set(Bushpig.job_key(job.job_id), job.job_payload, ex: ttl)
25
- conn.zadd(Bushpig.set_key(queue), score, job.job_id)
24
+ conn.set(Bushpig.job_key(modified.job_key), modified.job_payload, ex: ttl)
25
+ conn.zadd(Bushpig.queue_key(queue), score, modified.job_key)
26
26
  end
27
27
  end
28
28
  end
data/lib/bushpig/job.rb CHANGED
@@ -16,8 +16,12 @@ module Bushpig
16
16
  @job_id = job_id
17
17
  end
18
18
 
19
+ def job_key
20
+ job_id
21
+ end
22
+
19
23
  def job_payload
20
- JSON.generate({ class: self.class.name, args: each.to_a })
24
+ JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
21
25
  end
22
26
  end
23
27
  end
@@ -27,24 +31,30 @@ module Bushpig
27
31
  @@unique_key = unique_key
28
32
 
29
33
  def job_id
34
+ @job_id ||= SecureRandom.hex(32)
35
+ end
36
+
37
+ def job_id=(job_id)
38
+ @job_id = job_id
39
+ end
40
+
41
+ def job_key
30
42
  @@unique_key.inject(Digest::SHA256.new) do |digest, key|
31
43
  digest.update(self[key].to_s)
32
44
  end.hexdigest
33
45
  end
34
46
 
35
- def job_id=(job_id); end
36
-
37
47
  def job_payload
38
- JSON.generate({ class: self.class.name, args: each.to_a })
48
+ JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
39
49
  end
40
50
  end
41
51
  end
42
52
 
43
- def self.hydrate(job_id, job_payload)
53
+ def self.hydrate(job_payload)
44
54
  h = JSON.parse(job_payload, symbolize_names: true)
45
55
  klass = const_get(h[:class])
46
56
  job = klass.new(*h[:args])
47
- job.job_id = job_id
57
+ job.job_id = h[:id]
48
58
  job
49
59
  end
50
60
  end
@@ -48,7 +48,7 @@ module Bushpig
48
48
  end
49
49
 
50
50
  def handle(job)
51
- puts "Job starting: jid-#{job.job_id} #{job}"
51
+ puts "Job starting: jid-#{job.job_id} jkey-#{job.job_key} #{job}"
52
52
  started = monotonic_time
53
53
  @handler.call(job)
54
54
  finished = monotonic_time
@@ -70,7 +70,7 @@ module Bushpig
70
70
  end
71
71
 
72
72
  def notify_exception(job, exception)
73
- honeybadger&.notify(exception, context: { job_id: job.job_id, job: job.to_s })
73
+ honeybadger&.notify(exception, context: { job_id: job.job_id, job_key: job.job_key, job: job.to_s })
74
74
  end
75
75
 
76
76
  def monotonic_time
@@ -80,7 +80,7 @@ module Bushpig
80
80
  def fetch(queue)
81
81
  redis_pool.with do |conn|
82
82
  begin
83
- res = conn.bzpopmin(Bushpig.set_key(queue), @timeout)
83
+ res = conn.bzpopmin(Bushpig.queue_key(queue), @timeout)
84
84
  rescue Redis::TimeoutError
85
85
  # TODO: warn user (once) that redis timeout set lower than pop timeout
86
86
  conn.close
@@ -88,20 +88,20 @@ module Bushpig
88
88
  end
89
89
  return nil if res.nil?
90
90
 
91
- (_set, jid, _score) = res
92
- # conn.sadd('running', jid)
91
+ (_set, key, _score) = res
92
+ # conn.sadd('running', key)
93
93
 
94
- payload = conn.get(Bushpig.job_key(jid))
94
+ payload = conn.get(Bushpig.job_key(key))
95
95
  return nil if payload.nil? # most likely job expired
96
96
 
97
- Bushpig::Job.hydrate(jid, payload)
97
+ Bushpig::Job.hydrate(payload)
98
98
  end
99
99
  end
100
100
 
101
101
  def complete(job)
102
102
  redis_pool.with do |conn|
103
- # conn.srem('running', job.job_id)
104
- conn.del(Bushpig.job_key(job.job_id))
103
+ # conn.srem('running', job.job_key)
104
+ conn.del(Bushpig.job_key(job.job_key))
105
105
  end
106
106
  end
107
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bushpig
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bushpig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Sharples