pallets 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/pallets/logger.rb +14 -3
- data/lib/pallets/manager.rb +4 -3
- data/lib/pallets/scheduler.rb +3 -6
- data/lib/pallets/version.rb +1 -1
- data/lib/pallets/worker.rb +9 -14
- 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: c7ee0fbd91594f23bc84b81116f867490620f580223195f69fa9ff4f72be2558
|
4
|
+
data.tar.gz: b681bc765933ce36d3732a04eae3b9b7d60c2695b3d47f5704ebcfe96e3f884b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dfe6d23000df032d7f65fd81bd7907a3600240eaa6f111a161d1b2fb6d234440c8cc9219203a094ae139847ba00011939b50943e5eaaa04c11dde9128c3bb94
|
7
|
+
data.tar.gz: c054b1abd6d25b0408fa8427550751c8c8d41cd204bed65a968302d2ad5be98ac5ef020a6d096efc52ec58e9fef6f66456528ea72cdf423666916dd3a1394a5f
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.11.0] - 2020-10-09
|
10
|
+
### Added
|
11
|
+
- JSON logger (#62)
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- fix for leaking Redis connections (#61)
|
15
|
+
|
9
16
|
## [0.10.0] - 2020-08-30
|
10
17
|
### Added
|
11
18
|
- configure polling interval for scheduler (#60)
|
data/lib/pallets/logger.rb
CHANGED
@@ -9,8 +9,7 @@ module Pallets
|
|
9
9
|
metadata = Thread.current[:pallets_log_metadata]
|
10
10
|
return super(message) if metadata.nil?
|
11
11
|
|
12
|
-
|
13
|
-
super(formatted_metadata) { message }
|
12
|
+
super(metadata) { message }
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
@@ -24,7 +23,19 @@ module Pallets
|
|
24
23
|
module Formatters
|
25
24
|
class Pretty < ::Logger::Formatter
|
26
25
|
def call(severity, time, metadata, message)
|
27
|
-
"#{
|
26
|
+
formatted_metadata = ' ' + metadata.map { |k, v| "#{k}=#{v}" }.join(' ') if metadata
|
27
|
+
"#{time.utc.iso8601(4)} pid=#{Process.pid}#{formatted_metadata} #{severity}: #{message}\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Json < ::Logger::Formatter
|
32
|
+
def call(severity, time, metadata, message)
|
33
|
+
{
|
34
|
+
timestamp: time.utc.iso8601(4),
|
35
|
+
pid: Process.pid,
|
36
|
+
severity: severity,
|
37
|
+
message: message
|
38
|
+
}.merge(metadata || {}).to_json + "\n"
|
28
39
|
end
|
29
40
|
end
|
30
41
|
end
|
data/lib/pallets/manager.rb
CHANGED
@@ -3,8 +3,9 @@ module Pallets
|
|
3
3
|
attr_reader :workers, :scheduler
|
4
4
|
|
5
5
|
def initialize(concurrency: Pallets.configuration.concurrency)
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@backend = Pallets.backend
|
7
|
+
@workers = concurrency.times.map { Worker.new(self, @backend) }
|
8
|
+
@scheduler = Scheduler.new(self, @backend)
|
8
9
|
@lock = Mutex.new
|
9
10
|
@needs_to_stop = false
|
10
11
|
end
|
@@ -48,7 +49,7 @@ module Pallets
|
|
48
49
|
|
49
50
|
return if @needs_to_stop
|
50
51
|
|
51
|
-
worker = Worker.new(self)
|
52
|
+
worker = Worker.new(self, @backend)
|
52
53
|
@workers << worker
|
53
54
|
worker.start
|
54
55
|
end
|
data/lib/pallets/scheduler.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Pallets
|
2
2
|
class Scheduler
|
3
|
-
def initialize(manager)
|
3
|
+
def initialize(manager, backend)
|
4
4
|
@manager = manager
|
5
|
+
@backend = backend
|
5
6
|
@needs_to_stop = false
|
6
7
|
@thread = nil
|
7
8
|
end
|
@@ -35,7 +36,7 @@ module Pallets
|
|
35
36
|
loop do
|
36
37
|
break if needs_to_stop?
|
37
38
|
|
38
|
-
backend.reschedule_all(Time.now.to_f)
|
39
|
+
@backend.reschedule_all(Time.now.to_f)
|
39
40
|
wait_a_bit
|
40
41
|
end
|
41
42
|
end
|
@@ -55,9 +56,5 @@ module Pallets
|
|
55
56
|
sleep 1
|
56
57
|
end
|
57
58
|
end
|
58
|
-
|
59
|
-
def backend
|
60
|
-
@backend ||= Pallets.backend
|
61
|
-
end
|
62
59
|
end
|
63
60
|
end
|
data/lib/pallets/version.rb
CHANGED
data/lib/pallets/worker.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Pallets
|
2
2
|
class Worker
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(manager)
|
3
|
+
def initialize(manager, backend)
|
6
4
|
@manager = manager
|
5
|
+
@backend = backend
|
7
6
|
@current_job = nil
|
8
7
|
@needs_to_stop = false
|
9
8
|
@thread = nil
|
@@ -40,7 +39,7 @@ module Pallets
|
|
40
39
|
loop do
|
41
40
|
break if needs_to_stop?
|
42
41
|
|
43
|
-
@current_job = backend.pick
|
42
|
+
@current_job = @backend.pick
|
44
43
|
# No need to requeue because of the reliability queue
|
45
44
|
break if needs_to_stop?
|
46
45
|
next if @current_job.nil?
|
@@ -66,13 +65,13 @@ module Pallets
|
|
66
65
|
rescue
|
67
66
|
# We ensure only valid jobs are created. If something fishy reaches this
|
68
67
|
# point, just give up on it
|
69
|
-
backend.discard(job)
|
68
|
+
@backend.discard(job)
|
70
69
|
Pallets.logger.error "Could not deserialize #{job}. Gave up job"
|
71
70
|
return
|
72
71
|
end
|
73
72
|
|
74
73
|
context = Context[
|
75
|
-
serializer.load_context(backend.get_context(job_hash['wfid']))
|
74
|
+
serializer.load_context(@backend.get_context(job_hash['wfid']))
|
76
75
|
]
|
77
76
|
|
78
77
|
task_class = Pallets::Util.constantize(job_hash["task_class"])
|
@@ -103,9 +102,9 @@ module Pallets
|
|
103
102
|
))
|
104
103
|
if failures < job_hash['max_failures']
|
105
104
|
retry_at = Time.now.to_f + backoff_in_seconds(failures)
|
106
|
-
backend.retry(new_job, job, retry_at)
|
105
|
+
@backend.retry(new_job, job, retry_at)
|
107
106
|
else
|
108
|
-
backend.give_up(job_hash['wfid'], new_job, job)
|
107
|
+
@backend.give_up(job_hash['wfid'], new_job, job)
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
@@ -114,21 +113,17 @@ module Pallets
|
|
114
113
|
'given_up_at' => Time.now.to_f,
|
115
114
|
'reason' => 'returned_false'
|
116
115
|
))
|
117
|
-
backend.give_up(job_hash['wfid'], new_job, job)
|
116
|
+
@backend.give_up(job_hash['wfid'], new_job, job)
|
118
117
|
end
|
119
118
|
|
120
119
|
def handle_job_success(context, job, job_hash)
|
121
|
-
backend.save(job_hash['wfid'], job_hash['jid'], job, serializer.dump_context(context.buffer))
|
120
|
+
@backend.save(job_hash['wfid'], job_hash['jid'], job, serializer.dump_context(context.buffer))
|
122
121
|
end
|
123
122
|
|
124
123
|
def backoff_in_seconds(count)
|
125
124
|
count ** 4 + rand(6..10)
|
126
125
|
end
|
127
126
|
|
128
|
-
def backend
|
129
|
-
@backend ||= Pallets.backend
|
130
|
-
end
|
131
|
-
|
132
127
|
def serializer
|
133
128
|
@serializer ||= Pallets.serializer
|
134
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pallets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Horak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|