-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_savvy.rb
56 lines (46 loc) · 1.5 KB
/
config_savvy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'pallets'
class AnnounceProcessing
def self.call(worker, job, context)
puts "Starting to process job..."
yield
end
end
Pallets.configure do |c|
# Harness 4 Pallets workers per process
c.concurrency = 4
# The default one, though
c.backend = :redis
# Useful to connect to a hosted Redis instance. Takes all options `Redis.new`
# accepts, like `db`, `timeout`, `host`, `port`, `password`, `sentinels`.
# Check https://www.rubydoc.info/github/redis/redis-rb/Redis:initialize for
# more details
c.backend_args = { url: 'redis://127.0.0.1:6379/1' }
# Use a maximum of 10 backend connections (Redis, in this case)
c.pool_size = 10
# A tad faster than JSON
c.serializer = :msgpack
# Allow 10 minutes for a job to process. After this, we assume the job did not
# finish and we retry it
c.job_timeout = 600
# Jobs will be retried up to 5 times upon failure. After that, they will be
# given up. Retry times are exponential and happen after: 7, 22, 87, 262, ...
c.max_failures = 5
# Job execution can be wrapped with middleware to provide custom logic.
# Anything that responds to `call` would do
c.middleware << AnnounceProcessing
end
class ConfigSavvy < Pallets::Workflow
task 'Volatile'
task 'Success' => 'Volatile'
end
class Volatile < Pallets::Task
def run
raise 'I am randomly failing' if [true, false].sample
end
end
class Success < Pallets::Task
def run
puts 'I am executed after Volatile manages to successfully execute'
end
end
ConfigSavvy.new.run