lib/sidekiq/cron/job.rb in sidekiq-cron-0.1.4 vs lib/sidekiq/cron/job.rb in sidekiq-cron-0.1.5

- old
+ new

@@ -174,11 +174,11 @@ #set last run time @last_run_time = Time.parse(args['last_run_time'].to_s) rescue Time.now #get right arguments for job - @args = args["args"].nil? ? [] : (args["args"].is_a?(Array) ? args["args"] : [ args["args"] ]) + @args = args["args"].nil? ? [] : parse_args( args["args"] ) if args["message"] @message = args["message"] elsif @klass message_data = { @@ -264,11 +264,16 @@ else begin cron = CronParser.new(@cron) cron.next(Time.now) rescue Exception => e - errors << "'cron' -> #{@cron}: #{e.message}" + #fix for different versions of cron-parser + if e.message == "Bad Vixie-style specification bad" + errors << "'cron' -> #{@cron}: not a valid cronline" + else + errors << "'cron' -> #{@cron}: #{e.message}" + end end end errors << "'klass' (or class) must be set" if @klass.nil? || @klass.size == 0 @@ -356,9 +361,28 @@ def sort_name "#{status == "enabled" ? 0 : 1}_#{name}".downcase end private + + # Try parsing inbound args into an array. + # args from Redis will be encoded JSON; + # try to load JSON, then failover + # to string array. + def parse_args(args) + case args + when String + begin + Sidekiq.load_json(args) + rescue JSON::ParserError + [*args] # cast to string array + end + when Array + args # do nothing, already array + else + [*args] # cast to string array + end + end # Redis key for set of all cron jobs def self.jobs_key "cron_jobs" end