Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

joshgoebel/semi_daemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SemiDaemon

Why

Before this I've tried backgroundDRB, daemon_generator (I think that's the name), and they never really worked to my satisfaction. I did find background_job for scheduled background stuff and liked how simple it was to setup and get started. SemiDaemon is kind of patterned after the simplicity of setting up it's daemon process.

An example class

class CampaignSender < SemiDaemon

  # defaulted based on the name of the class if you don't provide them
  # log and pid will both be stored in your RAILS_ROOT/log folder
  log_file "campaign_sender.log"
  pid_file "campaign_sender.pid"

  # you must provide an interval that your work function is called
  interval 2.hours

  # your work function is called every 2 hours
  def work
    logger.info "Running the queue..."
    Campaign.run_queue!
  rescue StandardError => e
    logger.error "-----"
    logger.error e.message
    e.backtrace.each { |x| logger.error x }
    logger.error "-----"
  end

end

Setting it up with crontab

The following cron entry will start the daemon every hour. If the process is already running them the new process will simply quit.

0 * * * * /usr/bin/ruby /u/apps/your_app/current/script/runner -e production "CampaignSender.new.run"

If the process ever dies for any reason cron will send you the stack trace via e-mail (if you have that setup right). And one hour (or less) later the process will fire itself right back up again.

Enjoy,

Josh Goebel Dreamer3 on #rubyonrails/freenode

About

A "semi" daemon that's easy to configure and deploy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages