lib/belated/queue.rb in belated-0.5.4 vs lib/belated/queue.rb in belated-0.5.5

- old
+ new

@@ -1,24 +1,26 @@ # frozen_string_literal: true require 'belated/job' require 'belated/logging' require 'belated/job_wrapper' +require 'sorted_set' + class Belated class Queue include Logging attr_accessor :future_jobs FILE_NAME = 'belated_dump' - def initialize(queue: Thread::Queue.new, future_jobs: []) + def initialize(queue: Thread::Queue.new, future_jobs: SortedSet.new) @queue = queue self.future_jobs = future_jobs end def push(job) - if job == :shutdown || job.at.nil? || + if job.is_a?(Symbol) || job.at.nil? || job.at <= Time.now.utc @queue.push(job) else @future_jobs << job end @@ -77,9 +79,9 @@ end private def proc_or_shutdown?(job) - job.job.instance_of?(Proc) || job == :shutdown + job.job.instance_of?(Proc) || job.is_a?(Symbol) end end end