serial_scheduler 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/serial_scheduler/version.rb +1 -1
- data/lib/serial_scheduler.rb +9 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b83a00e72a7ae3fd8db2f2ee0e7096b893bd518f018c8698170d4803819efee
|
4
|
+
data.tar.gz: d68d671f5e1bd8fc10158b7e81288f6c81de5ca9f184ad4b2cb029f3c4879c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98d7363dd9ff8f7d23e9ed47e638d1daa4801f01fe9dce51881762ec6d3d97c351e0d5f31de2c7b5c9356bab674be28750897b21ba4b707d2824c667bb9f90c9
|
7
|
+
data.tar.gz: 5705053102ec7bc24cbad873fd2814661cdf9c04108873e37ddcdfded053f895c02dab3dc5a53bca466d13a3119042080f77519d817850aa5696b6d0f14d4177
|
data/lib/serial_scheduler.rb
CHANGED
@@ -8,7 +8,7 @@ class SerialScheduler
|
|
8
8
|
class Producer
|
9
9
|
attr_reader :name, :next, :timeout, :block
|
10
10
|
|
11
|
-
def initialize(name, interval: nil,
|
11
|
+
def initialize(name, timeout:, interval: nil, cron: nil, &block)
|
12
12
|
if cron
|
13
13
|
cron = Fugit.do_parse_cron(cron)
|
14
14
|
elsif !interval || interval < 1 || !interval.is_a?(Integer)
|
@@ -43,7 +43,7 @@ class SerialScheduler
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def initialize(logger: Logger.new(
|
46
|
+
def initialize(logger: Logger.new($stdout), error_handler: ->(e) { raise e })
|
47
47
|
@logger = logger
|
48
48
|
@error_handler = error_handler
|
49
49
|
|
@@ -52,8 +52,8 @@ class SerialScheduler
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# start a new thread that enqueues an execution at given interval
|
55
|
-
def add(*args, &block)
|
56
|
-
@producers << Producer.new(*args, &block)
|
55
|
+
def add(*args, **kwargs, &block)
|
56
|
+
@producers << Producer.new(*args, **kwargs, &block)
|
57
57
|
end
|
58
58
|
|
59
59
|
def run
|
@@ -70,6 +70,7 @@ class SerialScheduler
|
|
70
70
|
@logger.info message: "Waiting to start job", job: earliest.name, in: wait, at: target.to_s
|
71
71
|
loop do
|
72
72
|
break if @stopped || Time.now >= target # need to re-check or long waits will drift by .3%
|
73
|
+
|
73
74
|
sleep 1
|
74
75
|
end
|
75
76
|
end
|
@@ -89,12 +90,10 @@ class SerialScheduler
|
|
89
90
|
def execute_in_fork(producer)
|
90
91
|
@logger.info message: "Executing job", job: producer.name
|
91
92
|
pid = fork do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@error_handler.call(e)
|
97
|
-
end
|
93
|
+
Timeout.timeout producer.timeout, &producer.block
|
94
|
+
rescue StandardError => e # do not rescue `Exception` so it can be `Interrupt`-ed
|
95
|
+
@logger.error message: "Error in job", job: producer.name, error: e.message
|
96
|
+
@error_handler.call(e)
|
98
97
|
end
|
99
98
|
Process.wait pid
|
100
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serial_scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fugit
|
@@ -45,14 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
48
|
+
version: 2.5.0
|
49
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.2.16
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Simple scheduler for long-running and infrequent tasks, no threads, always
|