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 +4 -4
- data/Gemfile.lock +1 -1
- data/gemset.nix +1 -1
- data/lib/bushpig.rb +3 -3
- data/lib/bushpig/client.rb +3 -3
- data/lib/bushpig/job.rb +16 -6
- data/lib/bushpig/server.rb +9 -9
- data/lib/bushpig/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d3c78ffe7777e02a7e1a7d4f4e1838ab47c80a5c9d0c1d61e6547c2b956065f
|
4
|
+
data.tar.gz: 64bc3d1e149b54e84a28e9f637b9495b7a6e9d7eec451304e310afd8bb473067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1ca507019ef95f735f9b0558d1b4867fccec40a6fac62ced66f69d0ab57168a081af14dd661876221213c92e3c184393dabedefe8f706a1a12aa6354955bdd
|
7
|
+
data.tar.gz: 7148a4dabeff3df6575b455a08306342d9b488938593841882ed025e1f7a6fcbb35d22c5f29554a2269c78f3aa853808c84570d889aca8fadcac55ef5a362ec7
|
data/Gemfile.lock
CHANGED
data/gemset.nix
CHANGED
data/lib/bushpig.rb
CHANGED
@@ -43,11 +43,11 @@ module Bushpig
|
|
43
43
|
defined?(Bushpig::CLI)
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.
|
46
|
+
def self.queue_key(queue)
|
47
47
|
"set:#{queue}"
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.job_key(
|
51
|
-
"job:#{
|
50
|
+
def self.job_key(job_key)
|
51
|
+
"job:#{job_key}"
|
52
52
|
end
|
53
53
|
end
|
data/lib/bushpig/client.rb
CHANGED
@@ -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(
|
25
|
-
conn.zadd(Bushpig.
|
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(
|
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 =
|
57
|
+
job.job_id = h[:id]
|
48
58
|
job
|
49
59
|
end
|
50
60
|
end
|
data/lib/bushpig/server.rb
CHANGED
@@ -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.
|
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,
|
92
|
-
# conn.sadd('running',
|
91
|
+
(_set, key, _score) = res
|
92
|
+
# conn.sadd('running', key)
|
93
93
|
|
94
|
-
payload = conn.get(Bushpig.job_key(
|
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(
|
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.
|
104
|
-
conn.del(Bushpig.job_key(job.
|
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
|
data/lib/bushpig/version.rb
CHANGED