Class: RubyJob::InMemoryJobStore

Inherits:
JobStore
  • Object
show all
Defined in:
lib/ruby_job/in_memory_job_store.rb

Defined Under Namespace

Classes: JobPriorityQueue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from JobStore

#set

Constructor Details

#initializeInMemoryJobStore

Returns a new instance of InMemoryJobStore.



11
12
13
14
15
16
# File 'lib/ruby_job/in_memory_job_store.rb', line 11

def initialize
  super
  @semaphore = Mutex.new
  @next_uuid = 0
  @pause_starting_at = nil
end

Instance Attribute Details

#pause_starting_atObject (readonly)

Returns the value of attribute pause_starting_at.



9
10
11
# File 'lib/ruby_job/in_memory_job_store.rb', line 9

def pause_starting_at
  @pause_starting_at
end

Instance Method Details

#dequeue(job) ⇒ Object



24
25
26
# File 'lib/ruby_job/in_memory_job_store.rb', line 24

def dequeue(job)
  @semaphore.synchronize { queue.delete(job) }
end

#enqueue(job) ⇒ Object



18
19
20
21
22
# File 'lib/ruby_job/in_memory_job_store.rb', line 18

def enqueue(job)
  raise 'job does not have an assigned uuid' unless job.uuid

  @semaphore.synchronize { queue.push(job) }
end

#fetchObject



32
33
34
# File 'lib/ruby_job/in_memory_job_store.rb', line 32

def fetch
  @options[:wait] ? fetch_next_or_wait : fetch_next
end

#next_uuidObject



40
41
42
# File 'lib/ruby_job/in_memory_job_store.rb', line 40

def next_uuid
  @semaphore.synchronize { @next_uuid += 1 }
end

#pause_at(time) ⇒ Object



28
29
30
# File 'lib/ruby_job/in_memory_job_store.rb', line 28

def pause_at(time)
  @pause_starting_at = time
end

#sizeObject



36
37
38
# File 'lib/ruby_job/in_memory_job_store.rb', line 36

def size
  queue.size
end