delayed_job_master 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ac6f45642e4c4848deea50d7819bfef1f0d17b8c
4
- data.tar.gz: ac6ba6a5386a2f3d2cb72f495ce5c4bc06f5e266
2
+ SHA256:
3
+ metadata.gz: 548efefc42b3ecd02bcb85da66da4a8e001376057a54ee7a636adf5177346923
4
+ data.tar.gz: 6c83c6a641d334f262bb191f68649c90cfa083ede76ace8e960c9b7a1ce99b9d
5
5
  SHA512:
6
- metadata.gz: 74016c0784861d3f3b2c43b8ff6bc2cd2dfe2252918f4848d752073218aea50b53bb372307e823c9f9b3cf8dc596d5617a0b1d0740e1d12873e289e0fcc074c3
7
- data.tar.gz: 9ca2c253636b19f8810ba693ea9bc5c8ac6d2b8278a33aec12af5548cb17712f1f90cd0d94e8025daac1c539ffb805b84ee497ce86cdcd95cb61636b7ce1cdcb
6
+ metadata.gz: 81b40df17053df90e59c84c3e53bbc854ba0e623cc8185811725673867532f68525a65a86d732914f117f56788ebee607466d469e546f3be4332e2935ff17b60
7
+ data.tar.gz: c77e25e5aa04b6f4c11c3e7c630c3c8dcd45f691c5088cac3a8f07bb6980317419c1b5a45149c2154c4982991593f67f06bebef32dc27915e4d4958a05590981
data/.travis.yml CHANGED
@@ -4,11 +4,11 @@ services:
4
4
  rvm:
5
5
  - 2.3
6
6
  - 2.4
7
+ - 2.5
8
+ - 2.6
7
9
  gemfile:
8
10
  - gemfiles/active_record.gemfile
9
11
  - gemfiles/mongoid.gemfile
10
- before_install:
11
- - gem install bundler -v 1.15.3
12
12
  before_script:
13
13
  - cd spec/dummy
14
14
  - bundle exec rake db:migrate RAILS_ENV=test
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.2.0
4
+
5
+ * Add destroy_failed_jobs for worker.
6
+ * Get pid and worker instance in after_fork callback.
7
+ * Change config class for convenience.
8
+
9
+ ## 1.1.0
10
+
11
+ * Add monitor callback to verify database connection.
12
+ * Refactoring.
13
+
14
+ ## 1.0.0
15
+
16
+ * First release.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in delayed_job_master.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -80,6 +80,7 @@ add_worker do |worker|
80
80
  # worker.max_run_time 4.hours
81
81
  # worker.min_priority 1
82
82
  # worker.max_priority 10
83
+ # worker.destroy_failed_jobs true
83
84
  end
84
85
 
85
86
  # worker2
@@ -89,11 +90,11 @@ add_worker do |worker|
89
90
  worker.count 2
90
91
  end
91
92
 
92
- before_fork do |master, worker_info|
93
+ before_fork do |master, worker|
93
94
  Delayed::Worker.before_fork if defined?(Delayed::Worker)
94
95
  end
95
96
 
96
- after_fork do |master, worker_info|
97
+ after_fork do |master, worker|
97
98
  Delayed::Worker.after_fork if defined?(Delayed::Worker)
98
99
  end
99
100
 
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem "delayed_job_active_record", "~> 4.1.0"
4
+ gem "rails", "~> 5.2.0"
5
+ gem "sqlite3", "~> 1.3.6"
4
6
 
5
7
  gemspec path: "../"
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem "delayed_job_mongoid", "~> 2.3.0"
4
+ gem "rails", "~> 5.2.0"
5
+ gem "sqlite3", "~> 1.3.6"
4
6
 
5
7
  gemspec path: "../"
@@ -1,31 +1,29 @@
1
1
  require 'fileutils'
2
2
  require 'logger'
3
- require 'ostruct'
4
- require_relative 'util/file_reopener'
5
3
  require_relative 'master/version'
6
4
  require_relative 'master/command'
7
5
  require_relative 'master/callback'
8
- require_relative 'master/worker_info'
6
+ require_relative 'master/worker'
9
7
  require_relative 'master/worker_pool'
10
8
  require_relative 'master/signal_handler'
9
+ require_relative 'master/util/file_reopener'
11
10
 
12
11
  module Delayed
13
12
  class Master
14
- attr_reader :config, :logger, :worker_infos
13
+ attr_reader :config, :logger, :workers
15
14
 
16
15
  def initialize(argv)
17
- config = Command.new(argv).config
18
- @config = OpenStruct.new(config).freeze
16
+ @config = Command.new(argv).config
19
17
  @logger = setup_logger(@config.log_file, @config.log_level)
20
- @worker_infos = []
18
+ @workers = []
21
19
 
22
20
  @signal_handler = SignalHandler.new(self)
23
- @worker_pool = WorkerPool.new(self, config)
21
+ @worker_pool = WorkerPool.new(self, @config)
24
22
  end
25
23
 
26
24
  def run
27
25
  load_app
28
- show_worker_configs
26
+ show_config
29
27
  daemonize if @config.daemon
30
28
 
31
29
  create_pid_file
@@ -66,7 +64,7 @@ module Delayed
66
64
  def reopen_files
67
65
  @signal_handler.dispatch('USR1')
68
66
  @logger.info "reopening files..."
69
- Delayed::Util::FileReopener.reopen
67
+ Util::FileReopener.reopen
70
68
  @logger.info "reopened"
71
69
  end
72
70
 
@@ -106,9 +104,9 @@ module Delayed
106
104
  Process.daemon(true)
107
105
  end
108
106
 
109
- def show_worker_configs
110
- @config.worker_configs.each do |config|
111
- puts "#{config[:count]} worker for '#{config[:queues].join(',')}' under #{config[:control]} control"
107
+ def show_config
108
+ @config.workers.each do |setting|
109
+ puts "#{setting.count} worker for '#{setting.queues.join(',')}' under #{setting.control} control"
112
110
  end
113
111
  end
114
112
  end
@@ -1,12 +1,12 @@
1
1
  module Delayed
2
2
  class Master
3
3
  class Callback
4
- def initialize(config = {})
5
- @config = config.select { |k, _| Delayed::Master::DSL::CALLBACK_CONFIGS.include?(k) }
4
+ def initialize(config)
5
+ @callbacks = config.callbacks
6
6
  end
7
7
 
8
8
  def run(name, *args)
9
- @config[name].call(*args) if @config[name]
9
+ @callbacks[name].call(*args) if @callbacks[name]
10
10
  end
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  require 'optparse'
2
- require_relative 'dsl'
2
+ require_relative 'config'
3
3
 
4
4
  module Delayed
5
5
  class Master
@@ -7,7 +7,7 @@ module Delayed
7
7
  attr_reader :config
8
8
 
9
9
  def initialize(args)
10
- @config = {}
10
+ @config = Config.new
11
11
 
12
12
  OptionParser.new { |opt|
13
13
  opt.banner = <<-EOS
@@ -20,10 +20,10 @@ module Delayed
20
20
  exit
21
21
  end
22
22
  opt.on('-D', '--daemon', 'Start master as a daemon') do |boolean|
23
- @config[:daemon] = boolean
23
+ @config.daemon(boolean)
24
24
  end
25
25
  opt.on('-c', '--config=FILE', 'Specify config file') do |file|
26
- @config.merge!(DSL.new(file).config)
26
+ @config.read(file)
27
27
  end
28
28
  }.parse(args)
29
29
  end
@@ -0,0 +1,84 @@
1
+ module Delayed
2
+ class Master
3
+ class Config
4
+ SIMPLE_CONFIGS = [:working_directory, :log_file, :log_level, :pid_file, :monitor_wait, :daemon]
5
+ CALLBACK_CONFIGS = [:before_fork, :after_fork, :before_monitor, :after_monitor]
6
+
7
+ attr_reader :data, :workers
8
+
9
+ def initialize(file = nil)
10
+ @data = {}
11
+ @workers = []
12
+ read(file) if file
13
+ end
14
+
15
+ def read(file)
16
+ instance_eval(File.read(file))
17
+ end
18
+
19
+ def add_worker
20
+ worker = WorkerSetting.new(control: :static, count: 1)
21
+ yield worker
22
+ worker.exit_on_complete(true) if worker.control == :dynamic
23
+ @workers << worker
24
+ end
25
+
26
+ def callbacks
27
+ @data.select { |k, _| CALLBACK_CONFIGS.include?(k) }
28
+ end
29
+
30
+ SIMPLE_CONFIGS.each do |key|
31
+ define_method(key) do |value = nil|
32
+ if value
33
+ @data[key] = value
34
+ else
35
+ @data[key]
36
+ end
37
+ end
38
+ end
39
+
40
+ CALLBACK_CONFIGS.each do |key|
41
+ define_method(key) do |&block|
42
+ if block
43
+ @data[key] = block
44
+ else
45
+ @data[key]
46
+ end
47
+ end
48
+ end
49
+
50
+ class WorkerSetting
51
+ SIMPLE_CONFIGS = [:control, :count, :max_memory,
52
+ :min_priority, :max_priority, :sleep_delay, :read_ahead, :exit_on_complete,
53
+ :max_attempts, :max_run_time, :destroy_failed_jobs]
54
+ ARRAY_CONFIGS = [:queues]
55
+
56
+ attr_reader :data
57
+
58
+ def initialize(default = {})
59
+ @data = default
60
+ end
61
+
62
+ SIMPLE_CONFIGS.each do |key|
63
+ define_method(key) do |value = nil|
64
+ if value
65
+ @data[key] = value
66
+ else
67
+ @data[key]
68
+ end
69
+ end
70
+ end
71
+
72
+ ARRAY_CONFIGS.each do |key|
73
+ define_method(key) do |value = nil|
74
+ if value
75
+ @data[key] = Array(value)
76
+ else
77
+ @data[key]
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -4,11 +4,11 @@ module Delayed
4
4
  class Master
5
5
  class JobCounter
6
6
  class << self
7
- def count(config)
8
- jobs = ready_to_run(config[:max_run_time] || Delayed::Worker::DEFAULT_MAX_RUN_TIME)
9
- jobs.where!("priority >= ?", config[:min_priority]) if config[:min_priority]
10
- jobs.where!("priority <= ?", config[:max_priority]) if config[:max_priority]
11
- jobs.where!(queue: config[:queues]) if config[:queues].any?
7
+ def count(setting)
8
+ jobs = ready_to_run(setting.max_run_time || Delayed::Worker::DEFAULT_MAX_RUN_TIME)
9
+ jobs.where!("priority >= ?", setting.min_priority) if setting.min_priority
10
+ jobs.where!("priority <= ?", setting.max_priority) if setting.max_priority
11
+ jobs.where!(queue: setting.queues) if setting.queues.any?
12
12
  jobs.count
13
13
  end
14
14
 
@@ -4,12 +4,12 @@ module Delayed
4
4
  class Master
5
5
  class JobCounter
6
6
  class << self
7
- def count(config)
7
+ def count(setting)
8
8
  right_now = Delayed::Job.db_time_now
9
- jobs = reservation_criteria(right_now, config[:max_run_time] || Delayed::Worker::DEFAULT_MAX_RUN_TIME)
10
- jobs = jobs.gte(priority: config[:min_priority].to_i) if config[:min_priority]
11
- jobs = jobs.lte(priority: config[:max_priority].to_i) if config[:max_priority]
12
- jobs = jobs.any_in(queue: config[:queues]) if config[:queues].any?
9
+ jobs = reservation_criteria(right_now, setting.max_run_time || Delayed::Worker::DEFAULT_MAX_RUN_TIME)
10
+ jobs = jobs.gte(priority: setting.min_priority.to_i) if setting.min_priority
11
+ jobs = jobs.lte(priority: setting.max_priority.to_i) if setting.max_priority
12
+ jobs = jobs.any_in(queue: setting.queues) if setting.queues.any?
13
13
  jobs.count
14
14
  end
15
15
 
@@ -4,7 +4,7 @@ module Delayed
4
4
  def initialize(master)
5
5
  @master = master
6
6
  @logger = master.logger
7
- @worker_infos = master.worker_infos
7
+ @workers = master.workers
8
8
  end
9
9
 
10
10
  def register
@@ -28,9 +28,9 @@ module Delayed
28
28
  end
29
29
 
30
30
  def dispatch(signal)
31
- @worker_infos.each do |worker_info|
32
- next unless worker_info.pid
33
- dispatch_to(signal, worker_info.pid)
31
+ @workers.each do |worker|
32
+ next unless worker.pid
33
+ dispatch_to(signal, worker.pid)
34
34
  end
35
35
  end
36
36
 
@@ -0,0 +1,18 @@
1
+ module Delayed
2
+ class Master
3
+ class Util
4
+ class FileReopener
5
+ class << self
6
+ def reopen
7
+ ObjectSpace.each_object(File) do |file|
8
+ next if file.closed? || !file.sync
9
+ file.reopen file.path
10
+ file.sync = true
11
+ file.flush
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Delayed
2
2
  class Master
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,19 @@
1
+ module Delayed
2
+ class Master
3
+ class Worker
4
+ attr_reader :index, :setting
5
+ attr_accessor :pid, :instance
6
+
7
+ def initialize(index, setting)
8
+ @index = index
9
+ @setting = setting
10
+ end
11
+
12
+ def title
13
+ titles = ["delayed_job.#{@index}"]
14
+ titles << "(#{@setting.queues.join(',')})" if @setting.queues
15
+ titles.join(' ')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,27 +1,27 @@
1
1
  module Delayed
2
2
  class Master
3
3
  class WorkerPool
4
- def initialize(master, config = {})
4
+ def initialize(master, config)
5
5
  @master = master
6
- @logger = master.logger
7
- @worker_infos = master.worker_infos
6
+ @config = config
8
7
 
9
- @config = OpenStruct.new(config).freeze
10
- @static_worker_configs, @dynamic_worker_configs = @config.worker_configs.partition { |wc| wc[:control] == :static }
8
+ @logger = master.logger
9
+ @workers = master.workers
11
10
 
11
+ @static_settings, @dynamic_settings = config.workers.partition { |conf| conf.control == :static }
12
12
  @callback = Delayed::Master::Callback.new(config)
13
13
  end
14
14
 
15
15
  def init
16
- @static_worker_configs.each_with_index do |config, i|
17
- worker_info = Delayed::Master::WorkerInfo.new(i, config)
18
- @worker_infos << worker_info
19
- fork_worker(worker_info)
20
- @logger.info "started worker #{worker_info.pid}"
16
+ @static_settings.each_with_index do |setting, i|
17
+ worker = Delayed::Master::Worker.new(i, setting)
18
+ @workers << worker
19
+ fork_worker(worker)
20
+ @logger.info "started worker #{worker.pid}"
21
21
  end
22
22
 
23
23
  @prepared = true
24
- debug_worker_infos
24
+ print_workers
25
25
  end
26
26
 
27
27
  def monitor_while(&block)
@@ -41,28 +41,31 @@ module Delayed
41
41
 
42
42
  private
43
43
 
44
- def fork_worker(worker_info)
45
- @callback.run(:before_fork, @master, worker_info)
46
- worker_info.pid = fork do
47
- @callback.run(:after_fork, @master, worker_info)
48
- $0 = worker_info.title
49
- worker = create_new_worker(worker_info)
50
- worker.start
44
+ def fork_worker(worker)
45
+ @callback.run(:before_fork, @master, worker)
46
+ worker.pid = fork do
47
+ worker.pid = Process.pid
48
+ worker.instance = create_instance(worker)
49
+ @callback.run(:after_fork, @master, worker)
50
+ $0 = worker.title
51
+ worker.instance.start
51
52
  end
52
53
  end
53
54
 
54
- def create_new_worker(worker_info)
55
- worker = Delayed::Worker.new(worker_info.config)
56
- [:max_run_time, :max_attempts].each do |key|
57
- value = worker_info.config[key]
58
- Delayed::Worker.send("#{key}=", value) if value
55
+ def create_instance(worker)
56
+ instance = Delayed::Worker.new(worker.setting.data)
57
+ [:max_run_time, :max_attempts, :destroy_failed_jobs].each do |key|
58
+ if (value = worker.setting.send(key))
59
+ Delayed::Worker.send("#{key}=", value)
60
+ end
59
61
  end
60
62
  [:max_memory].each do |key|
61
- value = worker_info.config[key]
62
- worker.send("#{key}=", value) if value
63
+ if (value = worker.setting.send(key))
64
+ instance.send("#{key}=", value)
65
+ end
63
66
  end
64
- worker.master_logger = @logger
65
- worker
67
+ instance.master_logger = @logger
68
+ instance
66
69
  end
67
70
 
68
71
  def monitor
@@ -76,14 +79,14 @@ module Delayed
76
79
  def check_pid
77
80
  pid = wait_pid
78
81
  return unless pid
79
- worker_info = @worker_infos.detect { |wi| wi.pid == pid }
80
- return unless worker_info
82
+ worker = @workers.detect { |worker| worker.pid == pid }
83
+ return unless worker
81
84
 
82
- case worker_info.config[:control]
85
+ case worker.setting.control
83
86
  when :static
84
- fork_alt_worker(worker_info)
87
+ fork_alt_worker(worker)
85
88
  when :dynamic
86
- @worker_infos.delete(worker_info)
89
+ @workers.delete(worker)
87
90
  end
88
91
  end
89
92
 
@@ -94,43 +97,43 @@ module Delayed
94
97
  end
95
98
 
96
99
  def check_dynamic_worker
97
- @dynamic_worker_configs.each do |worker_config|
98
- current_count = @worker_infos.count { |wi| wi.config[:queues] == worker_config[:queues] }
99
- remaining_count = worker_config[:count] - current_count
100
- if remaining_count > 0 && (job_count = count_job_for_worker(worker_config)) > 0
100
+ @dynamic_settings.each do |setting|
101
+ current_count = @workers.count { |worker| worker.setting.queues == setting.queues }
102
+ remaining_count = setting.count - current_count
103
+ if remaining_count > 0 && (job_count = count_job(setting)) > 0
101
104
  [remaining_count, job_count].min.times do
102
- fork_dynamic_worker(worker_config)
105
+ fork_dynamic_worker(setting)
103
106
  end
104
107
  end
105
108
  end
106
109
  end
107
110
 
108
- def count_job_for_worker(worker_config)
109
- Delayed::Master::JobCounter.count(worker_config)
111
+ def count_job(setting)
112
+ Delayed::Master::JobCounter.count(setting)
110
113
  end
111
114
 
112
- def fork_dynamic_worker(worker_config)
113
- worker_info = Delayed::Master::WorkerInfo.new(@worker_infos.size, worker_config)
114
- @worker_infos << worker_info
115
+ def fork_dynamic_worker(setting)
116
+ worker = Delayed::Master::Worker.new(@workers.size, setting)
117
+ @workers << worker
115
118
 
116
119
  @logger.info "forking dynamic worker..."
117
- fork_worker(worker_info)
118
- @logger.info "forked worker #{worker_info.pid}"
120
+ fork_worker(worker)
121
+ @logger.info "forked worker #{worker.pid}"
119
122
 
120
- debug_worker_infos
123
+ print_workers
121
124
  end
122
125
 
123
- def fork_alt_worker(worker_info)
124
- @logger.info "worker #{worker_info.pid} seems to be killed, forking alternative worker..."
125
- fork_worker(worker_info)
126
- @logger.info "forked worker #{worker_info.pid}"
126
+ def fork_alt_worker(worker)
127
+ @logger.info "worker #{worker.pid} seems to be killed, forking alternative worker..."
128
+ fork_worker(worker)
129
+ @logger.info "forked worker #{worker.pid}"
127
130
 
128
- debug_worker_infos
131
+ print_workers
129
132
  end
130
133
 
131
- def debug_worker_infos
132
- @worker_infos.each do |worker_info|
133
- @logger.debug "#{worker_info.pid}: #{worker_info.title}"
134
+ def print_workers
135
+ @workers.each do |worker|
136
+ @logger.debug "#{worker.pid}: #{worker.title}"
134
137
  end
135
138
  end
136
139
  end
@@ -7,7 +7,7 @@ module Delayed
7
7
  trap('USR1') do
8
8
  Thread.new do
9
9
  master_logger.info "reopening files..."
10
- Delayed::Util::FileReopener.reopen
10
+ Delayed::Master::Util::FileReopener.reopen
11
11
  master_logger.info "reopened"
12
12
  end
13
13
  end
@@ -34,6 +34,7 @@ add_worker do |worker|
34
34
  # worker.max_run_time 4.hours
35
35
  # worker.min_priority 1
36
36
  # worker.max_priority 10
37
+ # worker.destroy_failed_jobs true
37
38
  end
38
39
 
39
40
  # worker2
@@ -43,11 +44,11 @@ add_worker do |worker|
43
44
  worker.count 2
44
45
  end
45
46
 
46
- before_fork do |master, worker_info|
47
+ before_fork do |master, worker|
47
48
  Delayed::Worker.before_fork if defined?(Delayed::Worker)
48
49
  end
49
50
 
50
- after_fork do |master, worker_info|
51
+ after_fork do |master, worker|
51
52
  Delayed::Worker.after_fork if defined?(Delayed::Worker)
52
53
  end
53
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshikazu Kaneta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-20 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: delayed_job
@@ -146,6 +146,7 @@ files:
146
146
  - ".gitignore"
147
147
  - ".rspec"
148
148
  - ".travis.yml"
149
+ - CHANGELOG.md
149
150
  - CODE_OF_CONDUCT.md
150
151
  - Gemfile
151
152
  - LICENSE.txt
@@ -157,15 +158,15 @@ files:
157
158
  - lib/delayed/master.rb
158
159
  - lib/delayed/master/callback.rb
159
160
  - lib/delayed/master/command.rb
160
- - lib/delayed/master/dsl.rb
161
+ - lib/delayed/master/config.rb
161
162
  - lib/delayed/master/job_counter.rb
162
163
  - lib/delayed/master/job_counter/active_record.rb
163
164
  - lib/delayed/master/job_counter/mongoid.rb
164
165
  - lib/delayed/master/signal_handler.rb
166
+ - lib/delayed/master/util/file_reopener.rb
165
167
  - lib/delayed/master/version.rb
166
- - lib/delayed/master/worker_info.rb
168
+ - lib/delayed/master/worker.rb
167
169
  - lib/delayed/master/worker_pool.rb
168
- - lib/delayed/util/file_reopener.rb
169
170
  - lib/delayed/worker/extension.rb
170
171
  - lib/delayed/worker/plugins/memory_checker.rb
171
172
  - lib/delayed/worker/plugins/signal_handler.rb
@@ -192,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.5.2.1
196
+ rubygems_version: 3.0.3
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: A simple delayed_job master process to control multiple workers
@@ -1,60 +0,0 @@
1
- module Delayed
2
- class Master
3
- class DSL
4
- SIMPLE_CONFIGS = [:working_directory, :log_file, :log_level, :pid_file, :monitor_wait]
5
- CALLBACK_CONFIGS = [:before_fork, :after_fork, :before_monitor, :after_monitor]
6
-
7
- attr_reader :config
8
-
9
- def initialize(config_file)
10
- @config = { worker_configs: [] }
11
- instance_eval(File.read(config_file))
12
- @config
13
- end
14
-
15
- def add_worker
16
- setting = WorkerSetting.new(control: :static, count: 1)
17
- yield setting
18
- setting.config[:exit_on_complete] = true if setting.config[:control] == :dynamic
19
- @config[:worker_configs] << setting.config
20
- end
21
-
22
- SIMPLE_CONFIGS.each do |key|
23
- define_method(key) do |value|
24
- @config[key] = value
25
- end
26
- end
27
-
28
- CALLBACK_CONFIGS.each do |key|
29
- define_method(key) do |&block|
30
- @config[key] = block
31
- end
32
- end
33
-
34
- class WorkerSetting
35
- SIMPLE_CONFIGS = [:control, :count, :max_memory,
36
- :min_priority, :max_priority, :sleep_delay, :read_ahead, :exit_on_complete,
37
- :max_attempts, :max_run_time]
38
- ARRAY_CONFIGS = [:queues]
39
-
40
- attr_reader :config
41
-
42
- def initialize(default = {})
43
- @config = default
44
- end
45
-
46
- SIMPLE_CONFIGS.each do |key|
47
- define_method(key) do |value|
48
- @config[key] = value
49
- end
50
- end
51
-
52
- ARRAY_CONFIGS.each do |key|
53
- define_method(key) do |value|
54
- @config[key] = Array(value)
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,19 +0,0 @@
1
- module Delayed
2
- class Master
3
- class WorkerInfo
4
- attr_reader :index, :config
5
- attr_accessor :pid
6
-
7
- def initialize(index, config = {})
8
- @index = index
9
- @config = config
10
- end
11
-
12
- def title
13
- titles = ["delayed_job.#{@index}"]
14
- titles << "(#{@config[:queues].join(',')})" if @config[:queues]
15
- titles.join(' ')
16
- end
17
- end
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- module Delayed
2
- class Util
3
- class FileReopener
4
- class << self
5
- def reopen
6
- ObjectSpace.each_object(File) do |file|
7
- next if file.closed? || !file.sync
8
- file.reopen file.path
9
- file.sync = true
10
- file.flush
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end