bushpig 0.1.7 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/gemset.nix +1 -1
- data/lib/bushpig/job.rb +27 -4
- data/lib/bushpig/server.rb +5 -1
- 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: 74a53f240f755c6d98d37f2790ac903fb3b6fd2b2470341c2dc357579605f51e
|
4
|
+
data.tar.gz: ddfc8337f32005071b941ea1dd6e1e1599fb7b27a8c2b3e72b941c95be26d25a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb792068441f32529b3075a9972a7f96c09cdcd64649dfa3d9a145e9bfb77502e85841ec9526a9612073a6d44b9f5f83951c0a458ce790ee0afe82330548a8d5
|
7
|
+
data.tar.gz: 578ab0ac3b7e9a69a8be8cd5df311caea42824267cfb44960b9519fe22015c56156b024082d8dd9e6d7e13bc949e54bce4357f21ff1420b7a6d3da31d4bbcadc
|
data/Gemfile.lock
CHANGED
data/gemset.nix
CHANGED
data/lib/bushpig/job.rb
CHANGED
@@ -6,8 +6,14 @@ require 'json'
|
|
6
6
|
|
7
7
|
module Bushpig
|
8
8
|
module Job
|
9
|
-
def self.job(*args)
|
9
|
+
def self.job(handler, *args)
|
10
10
|
Struct.new(*args) do
|
11
|
+
@job_handler = handler
|
12
|
+
|
13
|
+
def self.job_handler
|
14
|
+
@job_handler
|
15
|
+
end
|
16
|
+
|
11
17
|
def job_id
|
12
18
|
@job_id ||= SecureRandom.hex(32)
|
13
19
|
end
|
@@ -23,12 +29,25 @@ module Bushpig
|
|
23
29
|
def job_payload
|
24
30
|
JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
|
25
31
|
end
|
32
|
+
|
33
|
+
def handle
|
34
|
+
self.class.job_handler.call(self)
|
35
|
+
end
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
|
-
def self.keyed(unique_key, *args)
|
39
|
+
def self.keyed(handler, unique_key, *args)
|
30
40
|
Struct.new(*args) do
|
31
|
-
|
41
|
+
@job_handler = handler
|
42
|
+
@unique_key = unique_key
|
43
|
+
|
44
|
+
def self.job_handler
|
45
|
+
@job_handler
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.job_unique_key
|
49
|
+
@unique_key
|
50
|
+
end
|
32
51
|
|
33
52
|
def job_id
|
34
53
|
@job_id ||= SecureRandom.hex(32)
|
@@ -39,7 +58,7 @@ module Bushpig
|
|
39
58
|
end
|
40
59
|
|
41
60
|
def job_key
|
42
|
-
|
61
|
+
self.class.job_unique_key.inject(Digest::SHA256.new.update(self.class.name)) do |digest, key|
|
43
62
|
digest.update(self[key].to_s)
|
44
63
|
end.hexdigest
|
45
64
|
end
|
@@ -47,6 +66,10 @@ module Bushpig
|
|
47
66
|
def job_payload
|
48
67
|
JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
|
49
68
|
end
|
69
|
+
|
70
|
+
def handle
|
71
|
+
self.class.job_handler.call(self)
|
72
|
+
end
|
50
73
|
end
|
51
74
|
end
|
52
75
|
|
data/lib/bushpig/server.rb
CHANGED
@@ -37,7 +37,10 @@ module Bushpig
|
|
37
37
|
|
38
38
|
until @done
|
39
39
|
job = fetch(queue)
|
40
|
-
|
40
|
+
if job.nil?
|
41
|
+
ActiveRecord::Base.clear_active_connections!
|
42
|
+
next
|
43
|
+
end
|
41
44
|
|
42
45
|
handle(job)
|
43
46
|
complete(job)
|
@@ -59,6 +62,7 @@ module Bushpig
|
|
59
62
|
elapsed = finished - started
|
60
63
|
puts "Job raised exception: jid-#{job.job_id} #{elapsed} seconds: #{e}"
|
61
64
|
notify_exception(job, e)
|
65
|
+
ActiveRecord::Base.clear_active_connections!
|
62
66
|
end
|
63
67
|
|
64
68
|
def honeybadger
|
data/lib/bushpig/version.rb
CHANGED