Sha256: 4ff798a6114f58ad5ec70293f56ef92e8a99b1ac2c716978053d68dc5f362a69

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby

begin
  require './config/environment.rb'
  puts "Detected rails app has been loaded."
rescue LoadError
end

require 'ruby-clock'
require 'method_source'

class Rufus::Scheduler::Job
  def identifier
    @identifier ||= begin
      name || handler.source.split("\n").reject(&:empty?).grep_v(/#.*/)[-2].strip
    rescue
      begin
        source_location.join('-')
      rescue
        'error-calculating-job-identifier'
      end
    end
  end
end

RubyClock.instance.listen_to_signals
RubyClock.instance.prepare_rake
RubyClock.instance.schedule.pause



## Add methods to top-level namespace
def schedule
  RubyClock.instance.schedule
end

def on_error(&on_error_block)
  RubyClock.instance.on_error = on_error_block
  def schedule.on_error(job, error)
    RubyClock.instance.on_error.call(job, error)
  end
end

def around_action(&b)
  RubyClock.instance.around_actions << b
end

def cron(...)
  RubyClock.instance.schedule.cron(...)
end

def every(...)
  RubyClock.instance.schedule.every(...)
end

def shell(string)
  RubyClock.instance.shell(string)
end
#####################################


load ARGV[0] || 'Clockfile'

if defined?(::Rails)
  around_action do |job_proc|
    ::Rails.application.reloader.wrap do
      job_proc.call
    end
  end
end

RubyClock.instance.run_jobs

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-clock-2.0.0.beta3 exe/clock