Module: SimpleJob
- Defined in:
- lib/simple_job/job_queue.rb,
lib/simple_job.rb,
lib/simple_job/version.rb,
lib/simple_job/sqs_job_queue.rb,
lib/simple_job/job_definition.rb,
lib/simple_job/test_job_queue.rb
Overview
Requires the aws-sdk gem, which must be initialized for this API to be capable of queuing requests.
Synopsis:
include SimpleJob
JobQueue::DEFAULT.poll do ||
puts
end
Creating a queue implementation
To create a new queue implementation, just extend the SimpleJob::JobQueue class, and call the register_job_queue declaration with an identifier. The class must implement the get_queue class method and the enqueue/poll instance methods to fulfill the interface. The default_queue method may be overridden to set a default queue.
Example:
class ArrayQueue < SimpleJob::JobQueue
register_job_queue 'array', self
include Singleton
default self.instance
def self.get_queue(type, = {})
instance
end
def enqueue(, = {})
queue <<
end
def poll( = {}, &block)
= {
:interval => 1
}.merge()
loop do
= queue.shift
yield() if
Kernel.sleep([:interval])
end
end
private
def queue
@queue ||= []
end
end
Then you can use the new queue implementation by passing its identifier to JobQueue.config:
SimpleJob::JobQueue.config :implementation => 'array'
Defined Under Namespace
Modules: JobDefinition Classes: JobQueue, SQSJobQueue, TestJobQueue
Constant Summary collapse
- VERSION =
'0.13.0'