Class: Workerholic::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/workerholic/queue.rb

Overview

Handles background job enqueueing/dequeuing functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'workerholic:queue:main') ⇒ Queue

Returns a new instance of Queue.



6
7
8
9
10
# File 'lib/workerholic/queue.rb', line 6

def initialize(name = 'workerholic:queue:main')
  @storage = Storage::RedisWrapper.new
  @name = name
  @logger = LogManager.new
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/workerholic/queue.rb', line 4

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/workerholic/queue.rb', line 4

def name
  @name
end

#storageObject (readonly)

Returns the value of attribute storage.



4
5
6
# File 'lib/workerholic/queue.rb', line 4

def storage
  @storage
end

Instance Method Details

#dequeueObject



17
18
19
20
# File 'lib/workerholic/queue.rb', line 17

def dequeue
  job_info = storage.pop(name)
  job_info.last if job_info
end

#empty?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/workerholic/queue.rb', line 22

def empty?
  storage.list_length(name) == 0
end

#enqueue(serialized_job) ⇒ Object



12
13
14
15
# File 'lib/workerholic/queue.rb', line 12

def enqueue(serialized_job)
  storage.push(name, serialized_job)
  # logger.info("Your job was placed in the #{name} queue on #{Time.now}.")
end

#sizeObject



26
27
28
# File 'lib/workerholic/queue.rb', line 26

def size
  storage.list_length(name)
end