> sudo gem install daemons
Create new file and paste these codes at the below
/rails_app$ nano script/job_runner
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
daemon_options = {
:multiple => true,
:dir_mode => :normal,
:dir => File.join(dir, 'tmp', 'pids'),
:backtrace => true
}
Daemons.run_proc('job_runner', daemon_options) do
if ARGV.include?('--')
ARGV.slice! 0..ARGV.index('--')
else
ARGV.clear
end
Dir.chdir dir
RAILS_ENV = ARGV[1] || ENV['RAILS_ENV'] || 'development'
require File.join('config', 'environment')
Delayed::Worker.new.start
end
To start daemon, running this code > ruby script/job_runner start ENV_NAME
> ruby script/job_runner start development
Stop daemon, running this code > ruby script/job_runner stop ENV_NAME
> ruby script/job_runner stop development
No comments:
Post a Comment