belated 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/belated.rb +3 -21
- data/lib/belated/queue.rb +43 -1
- data/lib/belated/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed06672798a42b07c69c9dc84f32d1ba12a58a7b95028f0c4a2f5d1a5f0b04c4
|
4
|
+
data.tar.gz: 0ecf13b8abf076c5fbe8a0037017840e55f32c674f4a40092a6e35845503f4e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e16e639db3c05d9112a4b31232d0cb78dbe6fe93ed05cd33f1d9a7856ded7c40319c145c20cddf1dd5a8bafb2894d8f96d46fc423a6718180e4d5e4584fdc41
|
7
|
+
data.tar.gz: 86793a533285a0ae5761b3eb11d4f16fe44793cc83d2a24c6f7aebae6a4d27ff7795b3ef2e69ce7e2b12f5c86fb9e108d5252f2aa863c645262f880f0ad56cf7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.1] - 2021-08-05
|
4
|
+
|
5
|
+
- Now handles saving future jobs too! So if you have a job enqueued for tomorrow, and restart Belated, it should still be enqueued.
|
6
|
+
|
3
7
|
## [0.4.0] - 2021-08-03
|
4
8
|
|
5
9
|
- Now you can enqueue jobs to be done at a later time. Just pass an `at:` keyword param to the client.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,12 +8,13 @@ Note that Belated used to be called HardWorker. That name was already in use in
|
|
8
8
|
|
9
9
|
It uses dRuby to do the communication! Which is absolute great. No need for Redis or PostgreSQL, just Ruby standard libraries.
|
10
10
|
|
11
|
+
Can be used with or without Rails.
|
12
|
+
|
11
13
|
TODO LIST:
|
12
14
|
|
13
15
|
- Catch SIGTERM and friends
|
14
16
|
- Now supports it, partly.
|
15
17
|
- Don't crash on errors (Partially done)
|
16
|
-
- Save jobs enqueued at a future date too when quitting (now it only saves the jobs in the queue)
|
17
18
|
- Have multiple queues?
|
18
19
|
- Maybe support ActiveJob?
|
19
20
|
- Have a web UI
|
data/lib/belated.rb
CHANGED
@@ -22,7 +22,6 @@ class Belated
|
|
22
22
|
include Logging
|
23
23
|
include Singleton unless $TESTING
|
24
24
|
URI = 'druby://localhost:8788'
|
25
|
-
FILE_NAME = 'belated_dump'
|
26
25
|
@@queue = Belated::Queue.new
|
27
26
|
|
28
27
|
setting :rails, true
|
@@ -37,7 +36,7 @@ class Belated
|
|
37
36
|
# Aliased for testing purposes.
|
38
37
|
# This is only run from the bin file.
|
39
38
|
def start
|
40
|
-
boot_app && load_jobs
|
39
|
+
boot_app && @@queue.load_jobs
|
41
40
|
@worker_list = []
|
42
41
|
Belated.config.workers.times do |i|
|
43
42
|
@worker_list << Thread.new { Worker.new(number: i.next) }
|
@@ -97,20 +96,9 @@ class Belated
|
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
def load_jobs
|
101
|
-
log "reloading... if file exists #{File.exist?(Belated::FILE_NAME)}"
|
102
|
-
return unless File.exist?(Belated::FILE_NAME)
|
103
|
-
|
104
|
-
jobs = YAML.load(File.binread(FILE_NAME))
|
105
|
-
jobs.each do |job|
|
106
|
-
@@queue.push(job)
|
107
|
-
end
|
108
|
-
File.delete(Belated::FILE_NAME)
|
109
|
-
end
|
110
|
-
|
111
99
|
def reload
|
112
100
|
log 'reloading...'
|
113
|
-
load_jobs
|
101
|
+
@@queue.load_jobs
|
114
102
|
end
|
115
103
|
|
116
104
|
def stop_workers
|
@@ -118,13 +106,7 @@ class Belated
|
|
118
106
|
sleep 0.1 if worker.alive?
|
119
107
|
Thread.kill(worker)
|
120
108
|
end
|
121
|
-
|
122
|
-
@@queue.length.times do |_i|
|
123
|
-
unless (klass = @@queue.pop).instance_of?(Proc) || klass == :shutdown
|
124
|
-
class_array << klass
|
125
|
-
end
|
126
|
-
end
|
127
|
-
pp File.open(FILE_NAME, 'wb') { |f| f.write(YAML.dump(class_array)) }
|
109
|
+
@@queue.save_jobs
|
128
110
|
exit unless $TESTING
|
129
111
|
end
|
130
112
|
|
data/lib/belated/queue.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'belated/job'
|
4
|
+
require 'belated/logging'
|
3
5
|
class Belated
|
4
6
|
class Queue
|
7
|
+
include Logging
|
5
8
|
attr_accessor :future_jobs
|
6
9
|
|
10
|
+
FILE_NAME = 'belated_dump'
|
11
|
+
|
7
12
|
def initialize(queue: Thread::Queue.new, future_jobs: [])
|
8
13
|
@queue = queue
|
9
14
|
self.future_jobs = future_jobs
|
@@ -33,5 +38,42 @@ class Belated
|
|
33
38
|
def length
|
34
39
|
@queue.length
|
35
40
|
end
|
41
|
+
|
42
|
+
def load_jobs
|
43
|
+
log "reloading... if file exists #{File.exist?(FILE_NAME)}"
|
44
|
+
return unless File.exist?(FILE_NAME)
|
45
|
+
|
46
|
+
jobs = YAML.load(File.binread(FILE_NAME))
|
47
|
+
jobs.each do |job|
|
48
|
+
if job.is_a?(Job)
|
49
|
+
future_jobs.push(job)
|
50
|
+
else
|
51
|
+
@queue.push(job)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
File.delete(FILE_NAME)
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_jobs
|
58
|
+
class_array = []
|
59
|
+
@queue.length.times do |_i|
|
60
|
+
unless proc_or_shutdown?(klass = @queue.pop)
|
61
|
+
class_array << klass
|
62
|
+
end
|
63
|
+
end
|
64
|
+
future_jobs.each do |_job|
|
65
|
+
unless proc_or_shutdown?(klass = future_jobs.pop)
|
66
|
+
class_array << klass
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
pp File.open(FILE_NAME, 'wb') { |f| f.write(YAML.dump(class_array)) }
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def proc_or_shutdown?(job)
|
76
|
+
job.instance_of?(Proc) || job == :shutdown
|
77
|
+
end
|
36
78
|
end
|
37
79
|
end
|
data/lib/belated/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.1
|
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-08-
|
11
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: drb
|