belated 0.3.1 → 0.3.2

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: 99491dbba348e9e991f00436b70faa69d7ee3646961172014499a09276e9cb1e
4
- data.tar.gz: ebb40194db4cf9893edb0b06f6b940a4076e5ec328ea00ba2ab40bd839ebe7e6
3
+ metadata.gz: 995560f345bb7644aa19035b27a68d43a1210ee36c21d13e21cc430b76d9fded
4
+ data.tar.gz: 103441a7e60e79319c65bacbedfb4dc337224c41c0e9560225f3b2421e219473
5
5
  SHA512:
6
- metadata.gz: 0b40900814f6cae2396025fd6ebda46b6fedc11ae7bca92ffcd534cdd6a782e0cca581a264c6f0b3bac05c1c925de8d32590270370445dab62a8c50f9749df90
7
- data.tar.gz: 397925608f6083f3722e69661e7731d9f56557ee44d8b79e811b655a7d25dd2f58755f607ad00137296607dd6f1f3fe88045237152134769bb4b5b09aea5cb73
6
+ metadata.gz: ecc27c208d2fdb26c93ee39ebba7ada11236e9f564565d69258dfa6381a407c924e076365329f088ca4071955fd0eaeb8e9e1a1119f77d824473987590fee670
7
+ data.tar.gz: 57db27785351cbba33b6c704f877eacf4343d95a02267411e79bf63f1efadb49a67430342d145898a8571318bc61eafdd756bc2618388603122a0733bad7a3ed
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  .byebug_history
13
13
  /dummy/tmp/cache/
14
14
  /dummy/log/
15
- belated_dump
15
+ /dummy/log/test.log
16
+ belated_dump
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
 
4
4
 
5
+ ## [0.3.2] - 2021-07-31
6
+
7
+ - Trap INT and TERM, so now the shutdown is a little bit more graceful.
8
+
5
9
  ## [0.3.1] - 2021-07-29
6
10
 
7
11
  - Remove dummy app from gem... size should go down quite a bit.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belated (0.3.1)
4
+ belated (0.3.2)
5
5
  drb
6
6
  dry-configurable
7
7
 
data/README.md CHANGED
@@ -10,19 +10,23 @@ It uses dRuby to do the communication! Which is absolute great. No need for Redi
10
10
 
11
11
  TODO LIST:
12
12
 
13
- - ~~Marshal the job queue into a file so you don't lose all progress~~
14
- (Ended up using YAML)
15
13
  - Catch SIGTERM and friends
16
- - ~~Support Rails~~ (Supported!)
17
- - ~~Parse options from command line, eg. `--workers 10`~~(Done!)
14
+ - Now supports it, partly.
18
15
  - Don't crash on errors (Partially done)
19
- - ~~Add a logger~~
20
16
  - Make it possible to schedule jobs
21
17
  - Maybe support ActiveJob?
22
18
  - Have a web UI
23
19
  - Do some performance testing
24
20
  - Add a section telling people to use Sidekiq if they can
25
21
 
22
+ DONE
23
+
24
+ - ~~Marshal the job queue into a file so you don't lose all progress~~
25
+ (Ended up using YAML)
26
+ - ~~Add a logger~~
27
+ - ~~Support Rails~~ (Supported!)
28
+ - ~~Parse options from command line, eg. `--workers 10`~~(Done!)
29
+
26
30
  ## Installation
27
31
 
28
32
  Add this line to your application's Gemfile:
data/lib/belated.rb CHANGED
@@ -36,8 +36,7 @@ class Belated
36
36
  # Aliased for testing purposes.
37
37
  # This is only run from the bin file.
38
38
  def start
39
- boot_app
40
- load_jobs
39
+ boot_app && load_jobs
41
40
  @worker_list = []
42
41
  Belated.config.workers.times do |_i|
43
42
  @worker_list << Thread.new { Worker.new }
@@ -46,6 +45,7 @@ class Belated
46
45
 
47
46
  connect!
48
47
  banner_and_info
48
+ trap_signals
49
49
  DRb.thread.join
50
50
  end
51
51
  alias initialize start
@@ -55,12 +55,22 @@ class Belated
55
55
  DRb.start_service(URI, @@queue, verbose: true)
56
56
  rescue DRb::DRbConnError, Errno::EADDRINUSE
57
57
  Belated.logger.error 'Could not connect to DRb server.'
58
- uri = "druby://localhost:#{Array.new(4) { rand(10) }.join}"
59
- self.class.send(:remove_const, 'URI')
60
- self.class.const_set('URI', uri)
61
58
  retry
62
59
  end
63
60
 
61
+ def trap_signals
62
+ %w[INT TERM].each do |signal|
63
+ Signal.trap(signal) do
64
+ @worker_list.length.times do
65
+ @@queue.push(:shutdown)
66
+ end
67
+ Thread.new { stop_workers }
68
+ sleep 0.1 until @@queue.empty?
69
+ exit
70
+ end
71
+ end
72
+ end
73
+
64
74
  def boot_app
65
75
  return unless rails?
66
76
 
@@ -92,6 +102,7 @@ class Belated
92
102
 
93
103
  def stop_workers
94
104
  @worker_list&.each do |worker|
105
+ sleep 0.1 if worker.alive?
95
106
  Thread.kill(worker)
96
107
  end
97
108
  class_array = []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Belated
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -11,8 +11,9 @@ class Belated
11
11
 
12
12
  def start_working
13
13
  loop do
14
- job = Belated.fetch_job
15
- next unless job
14
+ next unless (job = Belated.fetch_job)
15
+
16
+ break if job == :shutdown
16
17
 
17
18
  log call_job(job)
18
19
  log 'fetching jobs...'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampo Kuokkanen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2021-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: drb
@@ -78,7 +78,6 @@ files:
78
78
  - bin/bundle
79
79
  - bin/console
80
80
  - bin/setup
81
- - hard_worker_dump
82
81
  - lib/belated.rb
83
82
  - lib/belated/client.rb
84
83
  - lib/belated/logging.rb
data/hard_worker_dump DELETED
@@ -1 +0,0 @@
1
- --- []