-
Notifications
You must be signed in to change notification settings - Fork 1
/
mqjob.rake
33 lines (27 loc) · 854 Bytes
/
mqjob.rake
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
namespace :mqjob do
task run: :environment do
workers = if ENV['WORKERS'].nil?
Mqjob.registed_class
else
ENV['WORKERS'].split(',').map{|x| x.is_a?(String) ? x.constantize : x}
end
if workers.empty?
puts "No workers found. Using format 「WORKERS=FooWorker,BarWorker bundle exec rake mqjob:run」"
exit(1)
end
threads = ENV['THREAD_SIZE'].to_i
threads = threads.zero? ? 10 : threads
db_pool_size = ActiveRecord::Base.connection_pool.size
if threads > db_pool_size
puts "WARN: threads size #{threads}, but database pool size is #{db_pool_size}!!"
end
pidfile = ENV['PIDFILE']
se = ServerEngine.create(
nil,
::Mqjob::WorkerGroup.configure(threads: threads, clazz: workers),
daemonize: Mqjob.daemonize,
pid_path: pidfile
)
se.run
end
end