bushpig 0.1.7 → 0.1.12

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: 8d3c78ffe7777e02a7e1a7d4f4e1838ab47c80a5c9d0c1d61e6547c2b956065f
4
- data.tar.gz: 64bc3d1e149b54e84a28e9f637b9495b7a6e9d7eec451304e310afd8bb473067
3
+ metadata.gz: 74a53f240f755c6d98d37f2790ac903fb3b6fd2b2470341c2dc357579605f51e
4
+ data.tar.gz: ddfc8337f32005071b941ea1dd6e1e1599fb7b27a8c2b3e72b941c95be26d25a
5
5
  SHA512:
6
- metadata.gz: 9a1ca507019ef95f735f9b0558d1b4867fccec40a6fac62ced66f69d0ab57168a081af14dd661876221213c92e3c184393dabedefe8f706a1a12aa6354955bdd
7
- data.tar.gz: 7148a4dabeff3df6575b455a08306342d9b488938593841882ed025e1f7a6fcbb35d22c5f29554a2269c78f3aa853808c84570d889aca8fadcac55ef5a362ec7
6
+ metadata.gz: cb792068441f32529b3075a9972a7f96c09cdcd64649dfa3d9a145e9bfb77502e85841ec9526a9612073a6d44b9f5f83951c0a458ce790ee0afe82330548a8d5
7
+ data.tar.gz: 578ab0ac3b7e9a69a8be8cd5df311caea42824267cfb44960b9519fe22015c56156b024082d8dd9e6d7e13bc949e54bce4357f21ff1420b7a6d3da31d4bbcadc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bushpig (0.1.7)
4
+ bushpig (0.1.12)
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.7";
189
+ version = "0.1.12";
190
190
  };
191
191
  coderay = {
192
192
  groups = ["default" "development"];
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
- @@unique_key = unique_key
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
- @@unique_key.inject(Digest::SHA256.new) do |digest, key|
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
 
@@ -37,7 +37,10 @@ module Bushpig
37
37
 
38
38
  until @done
39
39
  job = fetch(queue)
40
- next if job.nil?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bushpig
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.12'
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.7
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Sharples