bushpig 0.1.9 → 0.1.14

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: 75f414bd5b386fdcd5d452374ab9d6f1076e59353e6a08416cd710f8119f0b9b
4
- data.tar.gz: 91cca09ccea7aa3b9169d15fe8174d16312892c8db7668408f0c594afcdcaef2
3
+ metadata.gz: 50478f11ab72c719f2b8ef316866f3822370b9680bbf926b66ee6e981688057e
4
+ data.tar.gz: 7a5e2e7b548556b6484a8d2b5998cc5eb59b167023a972628c44a23646fe6cbd
5
5
  SHA512:
6
- metadata.gz: af10ea043bc302564ac0430b3531624c3d65b9c15cfc0e81e48f3cce9df314219b63c3bc1354de308420a6dd61d151858a9dcea1b9d999cdd23c201e9c12bcf3
7
- data.tar.gz: e45960eddf67527a28203e73c7805b14cdfd7fc0399fac5b18d99833ee1d9d054794d437fb30c69c1c6b405a910127d2118d1d8bc9a92839c9a28404ad9e4e2e
6
+ metadata.gz: a2f3d17d804d1de3e378274408c8109c9dd26895249624ed175ea3f2fcbb0ac52410931f5c0d09378306595c44060abe3bc2875737d95d84f04192d4dfe06b29
7
+ data.tar.gz: 588e4f398d33a51e15264b15709a45523f75a954f283d73317551e5f089a609bfdbd489f0c604eacd5c12136ca00edd6cf8a2a0cc44e35a72b1d25b214e19330
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bushpig (0.1.9)
4
+ bushpig (0.1.14)
5
5
  connection_pool (~> 2.2)
6
6
  json (>= 1.8)
7
7
  redis (~> 3.3)
@@ -16,15 +16,23 @@ GEM
16
16
  coderay (1.1.3)
17
17
  connection_pool (2.2.5)
18
18
  e2mmap (0.1.0)
19
+ io-wait (0.1.0)
19
20
  jaro_winkler (1.5.4)
20
- json (2.1.0)
21
+ json (2.5.1)
21
22
  kramdown (2.3.1)
22
23
  rexml
23
24
  kramdown-parser-gfm (1.1.0)
24
25
  kramdown (~> 2.0)
25
26
  method_source (1.0.0)
26
- mini_portile2 (2.5.1)
27
- nokogiri (1.11.3)
27
+ mini_portile2 (2.5.2)
28
+ net-ftp (~> 0.1)
29
+ net-ftp (0.1.2)
30
+ net-protocol
31
+ time
32
+ net-protocol (0.1.1)
33
+ io-wait
34
+ timeout
35
+ nokogiri (1.11.6)
28
36
  mini_portile2 (~> 2.5.0)
29
37
  racc (~> 1.4)
30
38
  parallel (1.20.1)
@@ -41,7 +49,7 @@ GEM
41
49
  reverse_markdown (2.0.0)
42
50
  nokogiri
43
51
  rexml (3.2.5)
44
- rubocop (1.14.0)
52
+ rubocop (1.15.0)
45
53
  parallel (~> 1.10)
46
54
  parser (>= 3.0.0.0)
47
55
  rainbow (>= 2.2.2, < 4.0)
@@ -50,10 +58,10 @@ GEM
50
58
  rubocop-ast (>= 1.5.0, < 2.0)
51
59
  ruby-progressbar (~> 1.7)
52
60
  unicode-display_width (>= 1.4.0, < 3.0)
53
- rubocop-ast (1.5.0)
61
+ rubocop-ast (1.7.0)
54
62
  parser (>= 3.0.1.1)
55
63
  ruby-progressbar (1.11.0)
56
- solargraph (0.40.4)
64
+ solargraph (0.41.0)
57
65
  backport (~> 1.1)
58
66
  benchmark
59
67
  bundler (>= 1.17.2)
@@ -69,6 +77,8 @@ GEM
69
77
  yard (~> 0.9, >= 0.9.24)
70
78
  thor (1.1.0)
71
79
  tilt (2.0.10)
80
+ time (0.1.0)
81
+ timeout (0.1.1)
72
82
  unicode-display_width (2.0.0)
73
83
  yard (0.9.26)
74
84
 
data/gemset.nix CHANGED
@@ -186,7 +186,7 @@
186
186
  path = ./.;
187
187
  type = "path";
188
188
  };
189
- version = "0.1.9";
189
+ version = "0.1.14";
190
190
  };
191
191
  coderay = {
192
192
  groups = ["default" "development"];
@@ -367,6 +367,16 @@
367
367
  };
368
368
  version = "0.1.0";
369
369
  };
370
+ io-wait = {
371
+ groups = ["default" "development"];
372
+ platforms = [];
373
+ source = {
374
+ remotes = ["https://rubygems.org"];
375
+ sha256 = "11zpcigndc11fkr2s6659d7nh1hj09zpmxlyqp9yq1mx76038s6w";
376
+ type = "gem";
377
+ };
378
+ version = "0.1.0";
379
+ };
370
380
  jaro_winkler = {
371
381
  groups = ["default" "development"];
372
382
  platforms = [];
@@ -531,10 +541,10 @@
531
541
  }];
532
542
  source = {
533
543
  remotes = ["https://rubygems.org"];
534
- sha256 = "01v6jjpvh3gnq6sgllpfqahlgxzj50ailwhj9b3cd20hi2dx0vxp";
544
+ sha256 = "0lrirj0gw420kw71bjjlqkqhqbrplla61gbv1jzgsz6bv90qr3ci";
535
545
  type = "gem";
536
546
  };
537
- version = "2.1.0";
547
+ version = "2.5.1";
538
548
  };
539
549
  kramdown = {
540
550
  dependencies = ["rexml"];
@@ -569,14 +579,37 @@
569
579
  version = "1.0.0";
570
580
  };
571
581
  mini_portile2 = {
582
+ dependencies = ["net-ftp"];
572
583
  groups = ["default" "development"];
573
584
  platforms = [];
574
585
  source = {
575
586
  remotes = ["https://rubygems.org"];
576
- sha256 = "0xg1x4708a4pn2wk8qs2d8kfzzdyv9kjjachg2f1phsx62ap2rx2";
587
+ sha256 = "0a2y04km3aciybk12yimkqn0ycrzy23iygl116n7addix9xdii3s";
577
588
  type = "gem";
578
589
  };
579
- version = "2.5.1";
590
+ version = "2.5.2";
591
+ };
592
+ net-ftp = {
593
+ dependencies = ["net-protocol" "time"];
594
+ groups = ["default" "development"];
595
+ platforms = [];
596
+ source = {
597
+ remotes = ["https://rubygems.org"];
598
+ sha256 = "1gx09b00k454fgn7q41r9xs5j5v9qj8xhfxnm650cns1ywcmzkil";
599
+ type = "gem";
600
+ };
601
+ version = "0.1.2";
602
+ };
603
+ net-protocol = {
604
+ dependencies = ["io-wait" "timeout"];
605
+ groups = ["default" "development"];
606
+ platforms = [];
607
+ source = {
608
+ remotes = ["https://rubygems.org"];
609
+ sha256 = "1ivxcqwgnrqbp2y0zpxz64in9a2cx9q9b0fxb630c51a1jaq63yz";
610
+ type = "gem";
611
+ };
612
+ version = "0.1.1";
580
613
  };
581
614
  nokogiri = {
582
615
  dependencies = ["mini_portile2" "racc"];
@@ -584,10 +617,10 @@
584
617
  platforms = [];
585
618
  source = {
586
619
  remotes = ["https://rubygems.org"];
587
- sha256 = "19d78mdg2lbz9jb4ph6nk783c9jbsdm8rnllwhga6pd53xffp6x0";
620
+ sha256 = "1z4x366icbl9w13pk50vxx5kywlksvhxqxrpv8f5xpjxfl3jl64z";
588
621
  type = "gem";
589
622
  };
590
- version = "1.11.3";
623
+ version = "1.11.6";
591
624
  };
592
625
  parallel = {
593
626
  groups = ["default" "development"];
@@ -847,10 +880,10 @@
847
880
  platforms = [];
848
881
  source = {
849
882
  remotes = ["https://rubygems.org"];
850
- sha256 = "0chjr6i0g7frbp7dhi4d83ppf7akkdaw7mcgcwbxd6a9mairafpp";
883
+ sha256 = "1xhay8qn3p5f3g6x8i6zh372zk5w2wjrv9dksysxal1r5brkly1w";
851
884
  type = "gem";
852
885
  };
853
- version = "1.14.0";
886
+ version = "1.15.0";
854
887
  };
855
888
  rubocop-ast = {
856
889
  dependencies = ["parser"];
@@ -858,10 +891,10 @@
858
891
  platforms = [];
859
892
  source = {
860
893
  remotes = ["https://rubygems.org"];
861
- sha256 = "0hx4im1a2qpiwipvsl3fma358ixjp4h0mhj56ichq15xrq709qlf";
894
+ sha256 = "1hnrfy928mwpa0ippqs4s8xwghwwp5h853naphgqxcd53l33chlv";
862
895
  type = "gem";
863
896
  };
864
- version = "1.5.0";
897
+ version = "1.7.0";
865
898
  };
866
899
  ruby-progressbar = {
867
900
  groups = ["default" "development"];
@@ -879,10 +912,10 @@
879
912
  platforms = [];
880
913
  source = {
881
914
  remotes = ["https://rubygems.org"];
882
- sha256 = "0xrad7amwf3nmdbif566qprk6xvwydxwz0s7arnzpvr01anc9gcl";
915
+ sha256 = "18daiaffwniprkfn9xq0njzqr8n37kw2605608njz2gz02m7b1rj";
883
916
  type = "gem";
884
917
  };
885
- version = "0.40.4";
918
+ version = "0.41.0";
886
919
  };
887
920
  thor = {
888
921
  groups = ["default"];
@@ -1053,6 +1086,26 @@
1053
1086
  };
1054
1087
  version = "2.0.10";
1055
1088
  };
1089
+ time = {
1090
+ groups = ["default" "development"];
1091
+ platforms = [];
1092
+ source = {
1093
+ remotes = ["https://rubygems.org"];
1094
+ sha256 = "1ayfwm8b0c6n0z34vwfpmy83lf1gd0mq7jbybzarkqp2ylmdlzvy";
1095
+ type = "gem";
1096
+ };
1097
+ version = "0.1.0";
1098
+ };
1099
+ timeout = {
1100
+ groups = ["default" "development"];
1101
+ platforms = [];
1102
+ source = {
1103
+ remotes = ["https://rubygems.org"];
1104
+ sha256 = "0lr1pp2hh6np1x9milzs4rim9sfpsb4izhs4dd5q5nnhkcwx8i63";
1105
+ type = "gem";
1106
+ };
1107
+ version = "0.1.1";
1108
+ };
1056
1109
  unicode-display_width = {
1057
1110
  groups = ["default" "development"];
1058
1111
  platforms = [];
data/lib/bushpig.rb CHANGED
@@ -6,6 +6,7 @@ require 'bushpig/redis_pool'
6
6
  require 'bushpig/job'
7
7
  require 'bushpig/client'
8
8
  require 'bushpig/server'
9
+ require 'bushpig/testing'
9
10
 
10
11
  module Bushpig
11
12
  NAME = 'Bushpig'
@@ -31,6 +32,14 @@ module Bushpig
31
32
  @server = server
32
33
  end
33
34
 
35
+ def self.testing
36
+ @testing ||= false
37
+ end
38
+
39
+ def self.testing=(testing)
40
+ @testing = testing
41
+ end
42
+
34
43
  def self.configure_server
35
44
  yield self if server?
36
45
  end
@@ -19,11 +19,16 @@ module Bushpig
19
19
  end
20
20
 
21
21
  def submit(queue, job, score: default_score, ttl: default_ttl)
22
- modified = @callback.call(job)
23
- redis_pool.with do |conn|
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
- end
22
+ new = if Bushpig.testing
23
+ job.handle
24
+ true
25
+ else
26
+ redis_pool.with do |conn|
27
+ conn.set(Bushpig.job_key(job.job_key), job.job_payload, ex: ttl)
28
+ conn.zadd(Bushpig.queue_key(queue), score, job.job_key)
29
+ end
30
+ end
31
+ @callback.call(job, new)
27
32
  end
28
33
  end
29
34
  end
data/lib/bushpig/job.rb CHANGED
@@ -30,8 +30,8 @@ module Bushpig
30
30
  JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
31
31
  end
32
32
 
33
- def call(job)
34
- self.class.job_handler.call(job)
33
+ def handle
34
+ self.class.job_handler.call(self)
35
35
  end
36
36
  end
37
37
  end
@@ -45,6 +45,10 @@ module Bushpig
45
45
  @job_handler
46
46
  end
47
47
 
48
+ def self.job_unique_key
49
+ @unique_key
50
+ end
51
+
48
52
  def job_id
49
53
  @job_id ||= SecureRandom.hex(32)
50
54
  end
@@ -54,7 +58,7 @@ module Bushpig
54
58
  end
55
59
 
56
60
  def job_key
57
- @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|
58
62
  digest.update(self[key].to_s)
59
63
  end.hexdigest
60
64
  end
@@ -63,8 +67,8 @@ module Bushpig
63
67
  JSON.generate({ class: self.class.name, id: job_id, args: each.to_a })
64
68
  end
65
69
 
66
- def call(job)
67
- self.class.job_handler.call(job)
70
+ def handle
71
+ self.class.job_handler.call(self)
68
72
  end
69
73
  end
70
74
  end
@@ -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
@@ -0,0 +1,14 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ module Bushpig
5
+ module Testing
6
+ def self.inline!(&block)
7
+ old = Bushpig.testing
8
+ Bushpig.testing = true
9
+ result = block.call
10
+ Bushpig.testing = old
11
+ result
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bushpig
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.14'
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.9
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Sharples
@@ -162,6 +162,7 @@ files:
162
162
  - lib/bushpig/job.rb
163
163
  - lib/bushpig/redis_pool.rb
164
164
  - lib/bushpig/server.rb
165
+ - lib/bushpig/testing.rb
165
166
  - lib/bushpig/version.rb
166
167
  - shell.nix
167
168
  homepage: https://github.com/mpowered/bushpig
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
192
193
  requirements: []
193
- rubygems_version: 3.1.3
194
+ rubygems_version: 3.2.16
194
195
  signing_key:
195
196
  specification_version: 4
196
197
  summary: Simple job system.