lib/belated/queue.rb in belated-0.6.6 vs lib/belated/queue.rb in belated-0.6.7
- old
+ new
@@ -17,18 +17,21 @@
FILE_NAME = 'belated_dump'
def initialize(queue: Thread::Queue.new, future_jobs: SortedSet.new)
@queue = queue
+ @mutex = Mutex.new
self.future_jobs = future_jobs
end
def push(job)
if job.is_a?(Symbol) || job.at.nil? ||
job.at <= Time.now.utc
@queue.push(job)
else
- @future_jobs << job
+ @mutex.synchronize do
+ @future_jobs << job
+ end
end
end
def pop
@queue.pop