delayed_job_master 2.0.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +31 -34
- data/.gitignore +0 -2
- data/CHANGELOG.md +13 -0
- data/README.md +46 -33
- data/delayed_job_master.gemspec +8 -5
- data/lib/delayed/master/callbacks.rb +37 -0
- data/lib/delayed/master/command.rb +28 -5
- data/lib/delayed/master/config.rb +51 -58
- data/lib/delayed/master/core.rb +146 -0
- data/lib/delayed/master/database.rb +72 -0
- data/lib/delayed/master/file_reopener.rb +18 -0
- data/lib/delayed/master/forker.rb +30 -19
- data/lib/delayed/master/job_checker.rb +91 -47
- data/lib/delayed/master/job_finder.rb +31 -0
- data/lib/delayed/master/job_listener.rb +31 -0
- data/lib/delayed/master/monitoring.rb +37 -36
- data/lib/delayed/master/postgresql/job_listener.rb +73 -0
- data/lib/delayed/master/postgresql/job_notifier.rb +45 -0
- data/lib/delayed/master/safe_array.rb +30 -0
- data/lib/delayed/master/signaler.rb +17 -7
- data/lib/delayed/master/sleep.rb +18 -0
- data/lib/delayed/master/worker/backend/active_record.rb +41 -0
- data/lib/delayed/master/worker/extension.rb +14 -0
- data/lib/delayed/master/worker/lifecycle.rb +10 -0
- data/lib/delayed/master/worker/plugins/all.rb +17 -0
- data/lib/delayed/master/worker/plugins/executor_wrapper.rb +23 -0
- data/lib/delayed/master/worker/plugins/memory_checker.rb +28 -0
- data/lib/delayed/master/worker/plugins/signal_handler.rb +35 -0
- data/lib/delayed/master/worker/plugins/status_notifier.rb +21 -0
- data/lib/delayed/master/worker/thread_pool.rb +64 -0
- data/lib/delayed/master/worker/thread_worker.rb +65 -0
- data/lib/delayed/master/worker.rb +8 -7
- data/lib/delayed/master/worker_setting.rb +72 -0
- data/lib/delayed/master.rb +7 -100
- data/lib/delayed_job_master/railtie.rb +16 -0
- data/lib/delayed_job_master/version.rb +5 -0
- data/lib/delayed_job_master.rb +15 -1
- data/lib/generators/delayed_job_master/templates/config.rb +14 -14
- data/lib/generators/delayed_job_master/templates/script +1 -1
- metadata +71 -17
- data/gemfiles/rails50.gemfile +0 -7
- data/gemfiles/rails51.gemfile +0 -7
- data/gemfiles/rails52.gemfile +0 -7
- data/lib/delayed/master/database_detector.rb +0 -37
- data/lib/delayed/master/job_counter.rb +0 -26
- data/lib/delayed/master/plugins/memory_checker.rb +0 -24
- data/lib/delayed/master/plugins/signal_handler.rb +0 -31
- data/lib/delayed/master/plugins/status_notifier.rb +0 -17
- data/lib/delayed/master/util/file_reopener.rb +0 -18
- data/lib/delayed/master/version.rb +0 -5
- data/lib/delayed/master/worker_extension.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc7748a97c2f7aa0869b23cc1e00fbc8682d9f527e9c151d77a018c227c218e
|
4
|
+
data.tar.gz: aa7ba20301d0881e0a76ae66e70a72a10b9baed00cd0137c0a7118f6fbdd1ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b34fa14373943cdaf4265a6076781d3e032916e8cc3b1f33c8da1a7fa4986309f99a329798213212dec17c1e0a8ba5c3ab4947b54802156e6dce30e6d044ea
|
7
|
+
data.tar.gz: 63ef8e75c2ee50e90e173a77b3d8a466208da366decf2caf199104e3468ce126cb86f4d2b8fdc3066795c8e699c41b8bc61b3475ab23d61ffc02c8ae582b75bf
|
data/.github/workflows/ci.yml
CHANGED
@@ -5,48 +5,41 @@ on: [push, pull_request]
|
|
5
5
|
jobs:
|
6
6
|
test:
|
7
7
|
runs-on: ubuntu-20.04
|
8
|
+
services:
|
9
|
+
postgres:
|
10
|
+
image: postgres:9.5
|
11
|
+
env:
|
12
|
+
POSTGRES_USER: postgres
|
13
|
+
POSTGRES_PASSWORD: postgres
|
14
|
+
ports:
|
15
|
+
- 5432:5432
|
16
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
17
|
+
mysql:
|
18
|
+
image: mysql:5.7
|
19
|
+
env:
|
20
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
21
|
+
ports:
|
22
|
+
- 3306:3306
|
23
|
+
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10
|
8
24
|
strategy:
|
9
25
|
fail-fast: false
|
10
26
|
matrix:
|
11
|
-
ruby: [2.
|
12
|
-
gemfile: ['
|
13
|
-
|
14
|
-
|
15
|
-
gemfile: rails60
|
16
|
-
- ruby: 2.3
|
17
|
-
gemfile: rails61
|
18
|
-
- ruby: 2.3
|
19
|
-
gemfile: rails70
|
20
|
-
- ruby: 2.4
|
21
|
-
gemfile: rails60
|
22
|
-
- ruby: 2.4
|
23
|
-
gemfile: rails61
|
24
|
-
- ruby: 2.4
|
25
|
-
gemfile: rails70
|
26
|
-
- ruby: 2.5
|
27
|
-
gemfile: rails70
|
28
|
-
- ruby: 2.6
|
29
|
-
gemfile: rails70
|
30
|
-
- ruby: 3.0
|
31
|
-
gemfile: rails50
|
32
|
-
- ruby: 3.0
|
33
|
-
gemfile: rails51
|
34
|
-
- ruby: 3.0
|
35
|
-
gemfile: rails52
|
36
|
-
- ruby: 3.1
|
37
|
-
gemfile: rails50
|
38
|
-
- ruby: 3.1
|
39
|
-
gemfile: rails51
|
40
|
-
- ruby: 3.1
|
41
|
-
gemfile: rails52
|
27
|
+
ruby: [2.7, '3.0', 3.1, 3.2]
|
28
|
+
gemfile: ['rails60', 'rails61', 'rails70']
|
29
|
+
database: ['postgresql', 'mysql']
|
30
|
+
database_config: ['default', 'multi']
|
42
31
|
|
43
|
-
name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}
|
32
|
+
name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}, ${{ matrix.database }}
|
44
33
|
|
45
34
|
env:
|
35
|
+
POSTGRES_USER: postgres
|
36
|
+
POSTGRES_PASSWORD: postgres
|
37
|
+
DATABASE: ${{ matrix.database }}
|
38
|
+
DATABASE_CONFIG: ${{ matrix.database_config }}
|
46
39
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
47
40
|
|
48
41
|
steps:
|
49
|
-
- uses: actions/checkout@
|
42
|
+
- uses: actions/checkout@v3
|
50
43
|
- uses: ruby/setup-ruby@v1
|
51
44
|
with:
|
52
45
|
ruby-version: ${{ matrix.ruby }}
|
@@ -54,8 +47,12 @@ jobs:
|
|
54
47
|
- name: Prepare test
|
55
48
|
run: |
|
56
49
|
cd spec/dummy
|
57
|
-
BUNDLE_GEMFILE=../../${{ env.BUNDLE_GEMFILE }} RAILS_ENV=test bundle exec rake
|
50
|
+
BUNDLE_GEMFILE=../../${{ env.BUNDLE_GEMFILE }} RAILS_ENV=test bundle exec rake db:create db:migrate
|
58
51
|
cd ../..
|
59
52
|
- name: Run test
|
60
53
|
run: |
|
61
54
|
bundle exec rspec
|
55
|
+
- name: Show log
|
56
|
+
run: |
|
57
|
+
cat spec/dummy/log/test.log
|
58
|
+
if: ${{ failure() }}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.0.0
|
4
|
+
|
5
|
+
* Add multithread feature for workers.
|
6
|
+
* Add graceful stop feature by WINCH signal.
|
7
|
+
* Add command line options.
|
8
|
+
* Add listen/notify feature for postgresql.
|
9
|
+
* Support multiple callbacks.
|
10
|
+
* Separate waitpid thread and job checker thread.
|
11
|
+
* Rename some configurations (`worker.count` to `worker.max_processes`, `monitor_wait` to `monitor_interval`).
|
12
|
+
* Use LIMIT query instead of COUNT query for finding jobs.
|
13
|
+
* Patch default SQL of delayed_job for postgresql.
|
14
|
+
* Drop support for ruby < 2.7 and rails < 6.0.
|
15
|
+
|
3
16
|
## 2.0.3
|
4
17
|
|
5
18
|
* Fix database config detection for rails 7.0.
|
data/README.md
CHANGED
@@ -4,26 +4,26 @@ A simple delayed_job master process to control multiple workers.
|
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* Support
|
7
|
+
* Support concurrent workers with multiprocess and multithread.
|
8
|
+
* Preload application and fork worker processes on demand.
|
9
|
+
* Check memory usage after processing a job to kill workers consuming large memory.
|
10
|
+
* Support signals for restarting master process / reopening log files.
|
11
|
+
* Check new jobs by polling multiple databases having delayed_jobs table.
|
12
|
+
* Detect new jobs quickly by using listen/notify feature. (only postgresql)
|
11
13
|
|
12
14
|
## Dependencies
|
13
15
|
|
14
|
-
* ruby 2.
|
16
|
+
* ruby 2.7+
|
17
|
+
* activesupport 6.0+
|
15
18
|
* delayed_job 4.1
|
16
|
-
|
17
|
-
## Supported delayed_job backends
|
18
|
-
|
19
|
-
* delayed_job_active_record 4.1
|
19
|
+
* delayed_job_active_record 4.1 (execlude sqlite)
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
23
23
|
Add this line to your application's Gemfile:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
gem 'delayed_job_master'
|
26
|
+
gem 'delayed_job_master'
|
27
27
|
```
|
28
28
|
|
29
29
|
And then execute:
|
@@ -36,7 +36,7 @@ Generate `bin/delayed_job_master` and `config/delayed_job_master.rb`:
|
|
36
36
|
|
37
37
|
$ rails generate delayed_job_master:config
|
38
38
|
|
39
|
-
##
|
39
|
+
## Configurations
|
40
40
|
|
41
41
|
Edit `config/delayed_job_master.rb`:
|
42
42
|
|
@@ -44,8 +44,11 @@ Edit `config/delayed_job_master.rb`:
|
|
44
44
|
# working directory
|
45
45
|
working_directory Dir.pwd
|
46
46
|
|
47
|
-
# monitor
|
48
|
-
|
47
|
+
# monitor interval for events (in seconds)
|
48
|
+
monitor_interval 5
|
49
|
+
|
50
|
+
# polling interval for new jobs (in seconds)
|
51
|
+
polling_interval 5
|
49
52
|
|
50
53
|
# path to pid file
|
51
54
|
pid_file "#{Dir.pwd}/tmp/pids/delayed_job_master.pid"
|
@@ -56,16 +59,19 @@ log_file "#{Dir.pwd}/log/delayed_job_master.log"
|
|
56
59
|
# log level
|
57
60
|
log_level :info
|
58
61
|
|
59
|
-
# databases for checking
|
60
|
-
# databases [:
|
62
|
+
# databases for checking new jobs in case multiple databases
|
63
|
+
# databases [:primary, :secondary]
|
61
64
|
|
62
65
|
# worker1
|
63
66
|
add_worker do |worker|
|
64
67
|
# queue name for the worker
|
65
68
|
worker.queues %w(queue1)
|
66
69
|
|
67
|
-
#
|
68
|
-
worker.
|
70
|
+
# max process count
|
71
|
+
worker.max_processes 1
|
72
|
+
|
73
|
+
# max thread count for each worker
|
74
|
+
worker.max_threads 1
|
69
75
|
|
70
76
|
# max memory in MB
|
71
77
|
worker.max_memory 300
|
@@ -83,22 +89,27 @@ end
|
|
83
89
|
# worker2
|
84
90
|
add_worker do |worker|
|
85
91
|
worker.queues %w(queue2)
|
86
|
-
worker.
|
92
|
+
worker.max_processes 2
|
93
|
+
worker.max_threads 2
|
87
94
|
end
|
88
95
|
|
89
96
|
before_fork do |master, worker|
|
90
|
-
|
97
|
+
ActiveRecord::Base.connection.disconnect!
|
91
98
|
end
|
92
99
|
|
93
100
|
after_fork do |master, worker|
|
94
|
-
|
101
|
+
ActiveRecord::Base.establish_connection
|
95
102
|
end
|
103
|
+
```
|
96
104
|
|
97
|
-
|
98
|
-
|
99
|
-
|
105
|
+
### Listen/notify
|
106
|
+
|
107
|
+
Listen/notify feature is enabled by default if `pg` gem is detected.
|
108
|
+
To disable this feature, put `config/initializers/delayed_job_master.rb` as follows:
|
100
109
|
|
101
|
-
|
110
|
+
```ruby
|
111
|
+
DelayedJobMaster.configure do |config|
|
112
|
+
config.listener = nil
|
102
113
|
end
|
103
114
|
```
|
104
115
|
|
@@ -113,11 +124,15 @@ Command line options:
|
|
113
124
|
* -c, --config: Specify configuration file.
|
114
125
|
* -D, --daemon: Start master as a daemon.
|
115
126
|
|
116
|
-
Stop master
|
127
|
+
Stop master immediately, stop workers gracefully:
|
117
128
|
|
118
129
|
$ kill -TERM `cat tmp/pids/delayed_job_master.pid`
|
119
130
|
|
120
|
-
Stop master and workers
|
131
|
+
Stop master and workers gracefully:
|
132
|
+
|
133
|
+
$ kill -WINCH `cat tmp/pids/delayed_job_master.pid`
|
134
|
+
|
135
|
+
Stop master and workers immediately:
|
121
136
|
|
122
137
|
$ kill -QUIT `cat tmp/pids/delayed_job_master.pid`
|
123
138
|
|
@@ -125,31 +140,30 @@ Reopen log files:
|
|
125
140
|
|
126
141
|
$ kill -USR1 `cat tmp/pids/delayed_job_master.pid`
|
127
142
|
|
128
|
-
Restart gracefully:
|
143
|
+
Restart master immediately, stop workers gracefully:
|
129
144
|
|
130
145
|
$ kill -USR2 `cat tmp/pids/delayed_job_master.pid`
|
131
146
|
|
132
147
|
Workers handle each signal as follows:
|
133
148
|
|
134
|
-
* TERM: Workers stop after finishing current jobs.
|
149
|
+
* TERM/WINCH/USR2: Workers stop after finishing current jobs.
|
135
150
|
* QUIT: Workers are killed immediately.
|
136
151
|
* USR1: Workers reopen log files.
|
137
|
-
* USR2: New workers start, old workers stop after finishing current jobs.
|
138
152
|
|
139
|
-
|
153
|
+
### Worker status
|
140
154
|
|
141
155
|
`ps` command shows worker status as follows:
|
142
156
|
|
143
157
|
```
|
144
158
|
$ ps aux
|
145
|
-
... delayed_job
|
159
|
+
... delayed_job: worker[0] (queue1) [BUSY] # BUSY process is currently proceeding some jobs
|
146
160
|
```
|
147
161
|
|
148
162
|
After graceful restart, you may find OLD process.
|
149
163
|
|
150
164
|
```
|
151
165
|
$ ps aux
|
152
|
-
... delayed_job
|
166
|
+
... delayed_job: worker[0] (queue1) [BUSY] [OLD] # OLD process will stop after finishing current jobs.
|
153
167
|
```
|
154
168
|
|
155
169
|
## Contributing
|
@@ -159,4 +173,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kanety
|
|
159
173
|
## License
|
160
174
|
|
161
175
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
162
|
-
|
data/delayed_job_master.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'delayed_job_master/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "delayed_job_master"
|
8
|
-
spec.version =
|
8
|
+
spec.version = DelayedJobMaster::VERSION
|
9
9
|
spec.authors = ["Yoshikazu Kaneta"]
|
10
10
|
spec.email = ["kaneta@sitebridge.co.jp"]
|
11
11
|
spec.summary = %q{A simple delayed_job master process to control multiple workers}
|
@@ -18,15 +18,18 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.7'
|
22
22
|
|
23
23
|
spec.add_dependency "delayed_job", ">= 4.1"
|
24
24
|
spec.add_dependency "get_process_mem"
|
25
|
+
spec.add_dependency "activesupport", ">= 6.0"
|
25
26
|
|
26
|
-
spec.add_development_dependency "rails"
|
27
|
+
spec.add_development_dependency "rails", ">= 6.0"
|
27
28
|
spec.add_development_dependency "rake"
|
28
29
|
spec.add_development_dependency "rspec-rails"
|
29
30
|
spec.add_development_dependency "simplecov"
|
30
|
-
spec.add_development_dependency "
|
31
|
+
spec.add_development_dependency "pg"
|
32
|
+
spec.add_development_dependency "mysql2"
|
31
33
|
spec.add_development_dependency "delayed_job_active_record", ">= 4.1"
|
34
|
+
spec.add_development_dependency "delayed_job_bulk", ">= 1.0.0"
|
32
35
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Delayed
|
4
|
+
module Master
|
5
|
+
class Callbacks
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(event, *args, &block)
|
11
|
+
run(:"before_#{event}", *args)
|
12
|
+
result = run(:"around_#{event}", *args, &block)
|
13
|
+
run(:"after_#{event}", *args)
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(name, *args, &block)
|
18
|
+
callbacks = get_callbacks(name)
|
19
|
+
if block
|
20
|
+
callbacks.reverse.reduce(block) { |ret, c| -> { c.call(*args, &ret) } }.call
|
21
|
+
else
|
22
|
+
callbacks.each { |c| c.call(*args) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_callbacks(name)
|
29
|
+
if @config.respond_to?(name)
|
30
|
+
@config.send(name).to_a
|
31
|
+
else
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
require_relative 'config'
|
3
5
|
|
4
6
|
module Delayed
|
5
|
-
|
7
|
+
module Master
|
6
8
|
class Command
|
7
9
|
attr_reader :config
|
8
10
|
|
@@ -11,7 +13,7 @@ module Delayed
|
|
11
13
|
|
12
14
|
OptionParser.new { |opt|
|
13
15
|
opt.banner = <<-EOS
|
14
|
-
#{File.basename($PROGRAM_NAME)} #{
|
16
|
+
#{File.basename($PROGRAM_NAME)} #{DelayedJobMaster::VERSION}
|
15
17
|
Usage: #{File.basename($PROGRAM_NAME)} [options]
|
16
18
|
EOS
|
17
19
|
|
@@ -19,12 +21,33 @@ module Delayed
|
|
19
21
|
puts opt
|
20
22
|
exit
|
21
23
|
end
|
22
|
-
opt.on('-D', '--daemon', 'Start master as a daemon') do |boolean|
|
23
|
-
@config.daemon(boolean)
|
24
|
-
end
|
25
24
|
opt.on('-c', '--config=FILE', 'Specify config file') do |file|
|
26
25
|
@config.read(file)
|
27
26
|
end
|
27
|
+
opt.on('-D', '--daemon', 'Start master as a daemon') do |boolean|
|
28
|
+
@config.daemon = boolean
|
29
|
+
end
|
30
|
+
opt.on('--working-directory=DIR', 'Path to working directory') do |dir|
|
31
|
+
@config.working_directory = dir
|
32
|
+
end
|
33
|
+
opt.on('--pid-file=FILE', 'Path to pid file') do |file|
|
34
|
+
@config.pid_file = file
|
35
|
+
end
|
36
|
+
opt.on('--log-file=FILE', 'Path to log file') do |file|
|
37
|
+
@config.log_file = file
|
38
|
+
end
|
39
|
+
opt.on('--log-level=LEVEL', 'Log level') do |level|
|
40
|
+
@config.log_level = level.to_sym
|
41
|
+
end
|
42
|
+
opt.on('--monitor-interval=INTERVAL', Numeric, 'Monitor interval') do |interval|
|
43
|
+
@config.monitor_interval = interval
|
44
|
+
end
|
45
|
+
opt.on('--polling-interval=INTERVAL', Numeric, 'Polling interval') do |interval|
|
46
|
+
@config.polling_interval = interval
|
47
|
+
end
|
48
|
+
opt.on('--databases=DB1,DB2', Array, 'Database spec name to check delayed_jobs table') do |databases|
|
49
|
+
@config.databases = databases.map(&:to_sym)
|
50
|
+
end
|
28
51
|
}.parse(args)
|
29
52
|
end
|
30
53
|
end
|
@@ -1,45 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'worker_setting'
|
4
|
+
|
1
5
|
module Delayed
|
2
|
-
|
6
|
+
module Master
|
3
7
|
class Config
|
4
|
-
SIMPLE_CONFIGS = [:working_directory, :log_file, :log_level, :pid_file,
|
5
|
-
|
8
|
+
SIMPLE_CONFIGS = [:daemon, :working_directory, :log_file, :log_level, :pid_file,
|
9
|
+
:monitor_interval, :polling_interval, :databases]
|
10
|
+
CALLBACK_CONFIGS = [:before_fork, :after_fork,
|
11
|
+
:before_monitor, :after_monitor, :around_monitor,
|
12
|
+
:before_polling, :after_polling, :around_polling]
|
6
13
|
|
7
|
-
|
14
|
+
attr_accessor *SIMPLE_CONFIGS
|
15
|
+
attr_accessor *CALLBACK_CONFIGS
|
16
|
+
attr_reader :workers
|
8
17
|
|
9
18
|
def initialize(file = nil)
|
10
|
-
@
|
19
|
+
@daemon = false
|
20
|
+
@working_directory = Dir.pwd
|
21
|
+
@pid_file = "#{@working_directory}/tmp/pids/delayed_job_master.pid"
|
22
|
+
@log_file = "#{@working_directory}/log/delayed_job_master.log"
|
23
|
+
@log_level = :info
|
24
|
+
@monitor_interval = 5
|
25
|
+
@polling_interval = 5
|
26
|
+
@databases = []
|
27
|
+
CALLBACK_CONFIGS.each do |name|
|
28
|
+
send("#{name}=", [])
|
29
|
+
end
|
11
30
|
@workers = []
|
12
31
|
read(file) if file
|
13
32
|
end
|
14
33
|
|
15
|
-
def worker_settings
|
16
|
-
@workers
|
17
|
-
end
|
18
|
-
|
19
34
|
def read(file)
|
20
35
|
instance_eval(File.read(file), file)
|
21
36
|
end
|
22
37
|
|
23
|
-
def
|
24
|
-
|
25
|
-
yield worker
|
26
|
-
@workers << worker
|
27
|
-
end
|
28
|
-
|
29
|
-
def callbacks
|
30
|
-
@data.select { |k, _| CALLBACK_CONFIGS.include?(k) }
|
38
|
+
def worker_settings
|
39
|
+
@workers
|
31
40
|
end
|
32
41
|
|
33
|
-
def
|
34
|
-
@
|
42
|
+
def add_worker
|
43
|
+
worker = WorkerSetting.new(id: @workers.size)
|
44
|
+
yield worker if block_given?
|
45
|
+
@workers << worker
|
46
|
+
worker
|
35
47
|
end
|
36
48
|
|
37
49
|
SIMPLE_CONFIGS.each do |key|
|
38
|
-
define_method(key) do |
|
39
|
-
if
|
40
|
-
|
50
|
+
define_method(key) do |*args|
|
51
|
+
if args.size > 0
|
52
|
+
instance_variable_set("@#{key}", args[0])
|
41
53
|
else
|
42
|
-
|
54
|
+
instance_variable_get("@#{key}")
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
@@ -47,48 +59,29 @@ module Delayed
|
|
47
59
|
CALLBACK_CONFIGS.each do |key|
|
48
60
|
define_method(key) do |&block|
|
49
61
|
if block
|
50
|
-
|
62
|
+
instance_variable_get("@#{key}") << block
|
51
63
|
else
|
52
|
-
|
64
|
+
instance_variable_get("@#{key}")
|
53
65
|
end
|
54
66
|
end
|
55
67
|
end
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
attr_reader :data
|
64
|
-
|
65
|
-
def initialize(default = {})
|
66
|
-
@data = default
|
67
|
-
end
|
68
|
-
|
69
|
-
def control(value = nil)
|
70
|
-
puts "DEPRECATION WARNING: deprecated control setting is called from #{caller(1, 1).first}. Remove it from your config file."
|
71
|
-
end
|
72
|
-
|
73
|
-
SIMPLE_CONFIGS.each do |key|
|
74
|
-
define_method(key) do |value = nil|
|
75
|
-
if !value.nil?
|
76
|
-
@data[key] = value
|
77
|
-
else
|
78
|
-
@data[key]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
69
|
+
def monitor_wait(value = nil)
|
70
|
+
ActiveSupport::Deprecation.warn <<-TEXT.squish
|
71
|
+
deprecated 'monitor_wait' setting was used. Use 'monitor_interval' instead."
|
72
|
+
TEXT
|
73
|
+
@monitor_interval = @polling_interval = value
|
74
|
+
end
|
82
75
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
76
|
+
def abstract_texts
|
77
|
+
texts = []
|
78
|
+
texts << "databases: #{@databases.join(', ')}" if @databases.present?
|
79
|
+
texts += @workers.map do |worker|
|
80
|
+
str = "worker[#{worker.id}]: #{worker.max_processes} processes, #{worker.max_threads} threads"
|
81
|
+
str += " (#{worker.queues.join(', ')})" if worker.queues.present?
|
82
|
+
str
|
91
83
|
end
|
84
|
+
texts
|
92
85
|
end
|
93
86
|
end
|
94
87
|
end
|