delayed_job 860 Bytes
#!/usr/bin/env ruby

## This is the Noosfero delayed job controller script. It starts and stops the
# delayed job daemon, which is implemented in the DelayedJob plugin.
#
# The role of this script is to just start/stop the daemon, write a PID file,
# etc. The actual feed update logic is DelayedJob plugin.

require 'daemons'

NOOSFERO_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')

options = {
  :dir_mode  => :normal,
  :dir       => File.dirname(__FILE__) + '/../tmp/pids',
  :multiple  => false,
  :backtrace => true,
  :monitor   => true,
}

Daemons.run_proc('job_runner', options) do
  if ARGV.include?('--')
    ARGV.slice! 0..ARGV.index('--')
  else
    ARGV.clear
  end

  Dir.chdir NOOSFERO_ROOT
  RAILS_ENV = ARGV.first || ENV['RAILS_ENV'] || 'development'
  require NOOSFERO_ROOT + '/config/environment'

  Delayed::Worker.new.start
end