Skip to content

Instantly share code, notes, and snippets.

@haoch
Last active August 29, 2015 14:00
Show Gist options
  • Save haoch/11314038 to your computer and use it in GitHub Desktop.
Save haoch/11314038 to your computer and use it in GitHub Desktop.

Lightweight Daemond Scheduler Solution

Run

ruby daemond.rb start

Why not use Daemons.run_proc?

When use Daemons.run, the scheduler will correctly restart once it cashed. But Daemons.run_proc seems not to work at all except restart the process.

require 'rubygems'
require 'daemons'
Daemons.run 'scheduler.rb', :dir_mod => :write,
:dir => "#{File.dirname(__FILE__)}/tmp/pids",
:backtrace => true,
:monitor => true,
:log_output => true
source 'https://rubygems.org'
gem 'rufus-scheduler'
gem 'daemons'
require 'rubygems'
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
times = 1
log = "#{File.dirname(__FILE__)}/scheduler.log"
scheduler.every '3s' do
# Do something
puts "==>times: #{times}"
File.write( log,"times: #{times}")
times += 1
end
scheduler.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment