Sha256: af7efe5b7d142bf63abf50fa9fa9fb986632379399f5736d138b27bcca59f983

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

#!/usr/bin/env ruby

require 'ruby-clock'
require "ruby-clock/dsl"
RubyClock.detect_and_load_rails_app
require 'rufus_monkeypatch'
RubyClock.instance.listen_to_signals
RubyClock.instance.prepare_rake
RubyClock.instance.schedule.pause
RubyClock.instance.add_rails_executor_to_around_actions

check_syntax = false
check_slug_uniqueness = false
generate_dummy_crontab = false
if '--' == ARGV[0][0..1]
  case ARGV[0]
  when '--environment-and-syntax-check'
    check_syntax = true
  when '--check-slug-uniqueness'
    check_slug_uniqueness = true
  when '--generate-dummy-crontab'
    generate_dummy_crontab = true
  else
    raise 'unknown option'
  end
  if ARGV[1]
    clockfiles = ARGV[1..]
  else
    clockfiles = ['Clockfile']
  end
else
  if ARGV[0]
    clockfiles = ARGV[0..]
  else
    clockfiles = ['Clockfile']
  end
end

clockfiles.each do |clockfile|
  begin
    load clockfile
  rescue => clockfile_error
    if RubyClock.instance.on_error
      RubyClock.instance.on_error.call("An error has occured while parsing the clockfile #{clockfile}", clockfile_error)
    end

    raise
  end
end

RubyClock.instance.ensure_around_trigger_has_not_been_redefined
RubyClock.instance.freeze_around_actions

if check_syntax
  puts "✨ Environment & Syntax OK ✨"
elsif check_slug_uniqueness
  slugs = {}
  RubyClock.instance.schedule.jobs.each do |j|
    if slugs[j.slug]
      slugs[j.slug] +=1
    else
      slugs[j.slug] = 1
    end
  end
  slugs_with_duplicates = []
  slugs.each{|s,count| slugs_with_duplicates << s if count > 1 }
  if slugs_with_duplicates.any?
    puts "The following slugs have duplicates: #{slugs_with_duplicates}"
    exit(false)
  else
    puts "✨ All Slugs Are Unique ✨"
  end
elsif generate_dummy_crontab
  text = ''
  RubyClock.instance.schedule.jobs.each do |j|
    if j.respond_to?(:cron_line)
      text << "#{j.cron_line.original} #{j.slug}\n"
    else
      text << "# every-#{j.frequency}-seconds #{j.slug}\n"
    end
  end
  puts text
else
  RubyClock.instance.run_jobs
end

Version data entries

2 entries across 2 versions & 1 rubygems

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