lib/sidekiq/cron/job.rb in sidekiq-cron-0.4.0 vs lib/sidekiq/cron/job.rb in sidekiq-cron-0.4.1
- old
+ new
@@ -14,11 +14,14 @@
#crucial part of whole enquing job
def should_enque? time
enqueue = false
enqueue = Sidekiq.redis do |conn|
- status == "enabled" && not_enqueued_after?(time) && conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time))
+ status == "enabled" &&
+ not_past_scheduled_time?(time) &&
+ not_enqueued_after?(time) &&
+ conn.zadd(job_enqueued_key, formated_enqueue_time(time), formated_last_time(time))
end
enqueue
end
# remove previous informations about run times
@@ -431,10 +434,14 @@
# time when last run should be performed
def last_time now = Time.now
Rufus::Scheduler::CronLine.new(@cron).previous_time(now)
end
+ def formated_enqueue_time now = Time.now
+ last_time(now).getutc.to_f.to_s
+ end
+
def formated_last_time now = Time.now
last_time(now).getutc.iso8601
end
def self.exists? name
@@ -476,9 +483,15 @@
when Array
args # do nothing, already array
else
[*args] # cast to string array
end
+ end
+
+ def not_past_scheduled_time?(current_time)
+ last_cron_time = Rufus::Scheduler::CronLine.new(@cron).previous_time(current_time)
+ return false if (current_time - last_cron_time) > 60
+ true
end
# Redis key for set of all cron jobs
def self.jobs_key
"cron_jobs"