lib/belated/queue.rb in belated-0.4.4 vs lib/belated/queue.rb in belated-0.5.0
- old
+ new
@@ -1,9 +1,10 @@
# frozen_string_literal: true
require 'belated/job'
require 'belated/logging'
+require 'belated/job_wrapper'
class Belated
class Queue
include Logging
attr_accessor :future_jobs
@@ -12,15 +13,15 @@
def initialize(queue: Thread::Queue.new, future_jobs: [])
@queue = queue
self.future_jobs = future_jobs
end
- def push(job, at: nil)
- if at.nil?
+ def push(job)
+ if job.at.nil? || job.at <= Time.now.utc
@queue.push(job)
else
- @future_jobs << Job.new(job, at)
+ @future_jobs << job
end
end
def pop
@queue.pop
@@ -43,11 +44,11 @@
log "reloading... if file exists #{File.exist?(FILE_NAME)}"
return unless File.exist?(FILE_NAME)
jobs = YAML.load(File.binread(FILE_NAME))
jobs.each do |job|
- if job.is_a?(Job)
+ if job.at && job.at > Time.now.utc
future_jobs.push(job)
else
@queue.push(job)
end
end
@@ -71,9 +72,9 @@
end
private
def proc_or_shutdown?(job)
- job.instance_of?(Proc) || job == :shutdown
+ job.job.instance_of?(Proc) || job == :shutdown
end
end
end