redis3m  1.0.0
All Classes Functions Variables Enumerations Pages
Public Member Functions | List of all members
redis3m::patterns::scheduler Class Reference

A scheduler pattern, can be useful to manage "jobs" that needs to be run at a given time. It's fault tolerant and scalable. Multiple workers can be dispatched and jobs will be executed only once. See http://luca3m.me/2013/12/03/redis-scheduler.html for other infos. More...

#include <scheduler.h>

Public Member Functions

 scheduler (const std::string &queue_name)
 Scheduler constructor. More...
 
void append_enqueue (connection::ptr_t connection, const std::string &object_id, const boost::posix_time::ptime &time)
 Append Redis commands needed to enqueue a job, useful to use inside transactions. More...
 
void append_enqueue (connection::ptr_t connection, const std::string &object_id, const boost::posix_time::time_duration &delay)
 Append Redis commands needed to enqueue a job, useful to use inside transactions. More...
 
void enqueue (connection::ptr_t connection, const std::string &object_id, const boost::posix_time::ptime &time)
 Put a job in schedule. More...
 
void enqueue (connection::ptr_t connection, const std::string &object_id, const boost::posix_time::time_duration &delay)
 Put a job in schedule. More...
 
void append_dequeue (connection::ptr_t connection, const std::string &object_id)
 Append Redis commands to remove a job from queue, use it when worker ends a job. Otherwise it will fire on another worker. It's like dequeue() but to be used inside transactions. More...
 
void dequeue (connection::ptr_t connection, const std::string &object_id)
 Remove a job from queue, use it when worker ends a job. Otherwise it will fire on another worker. More...
 
std::string find_expired (connection::ptr_t connection, const boost::posix_time::time_duration &lock_for=boost::posix_time::seconds(60))
 Return a fired job, it will be locked for an amount of time. During this time the worker will run the job and then call dequeue(). If worker crashes, the job will fire on another worker after lock period. More...
 

Detailed Description

A scheduler pattern, can be useful to manage "jobs" that needs to be run at a given time. It's fault tolerant and scalable. Multiple workers can be dispatched and jobs will be executed only once. See http://luca3m.me/2013/12/03/redis-scheduler.html for other infos.

Constructor & Destructor Documentation

scheduler::scheduler ( const std::string &  queue_name)

Scheduler constructor.

Parameters
queue_nameredis key used to store jobs, in a ZSET

Member Function Documentation

void scheduler::append_dequeue ( connection::ptr_t  connection,
const std::string &  object_id 
)

Append Redis commands to remove a job from queue, use it when worker ends a job. Otherwise it will fire on another worker. It's like dequeue() but to be used inside transactions.

Parameters
connection
object_id
void scheduler::append_enqueue ( connection::ptr_t  connection,
const std::string &  object_id,
const boost::posix_time::ptime &  time 
)

Append Redis commands needed to enqueue a job, useful to use inside transactions.

Parameters
connectiona valid redis connection
object_idan object id, can be everything, like a reference to an Redis hash
timeabsolute UTC time, when job will fire
void scheduler::append_enqueue ( connection::ptr_t  connection,
const std::string &  object_id,
const boost::posix_time::time_duration &  delay 
)

Append Redis commands needed to enqueue a job, useful to use inside transactions.

Parameters
connectiona valid redis connection
object_idan object id, can be everything, like a reference to an Redis hash
delayJob will fire at now() + delay
void scheduler::dequeue ( connection::ptr_t  connection,
const std::string &  object_id 
)

Remove a job from queue, use it when worker ends a job. Otherwise it will fire on another worker.

Parameters
connection
object_id
void scheduler::enqueue ( connection::ptr_t  connection,
const std::string &  object_id,
const boost::posix_time::ptime &  time 
)

Put a job in schedule.

Parameters
connectiona valid redis connection
object_idan object id, can be everything, like a reference to an Redis hash
timeabsolute UTC time, when job will fire
void scheduler::enqueue ( connection::ptr_t  connection,
const std::string &  object_id,
const boost::posix_time::time_duration &  delay 
)

Put a job in schedule.

Parameters
connectiona valid redis connection
object_idan object id, can be everything, like a reference to an Redis hash
delayJob will fire at now() + delay
std::string scheduler::find_expired ( connection::ptr_t  connection,
const boost::posix_time::time_duration &  lock_for = boost::posix_time::seconds(60) 
)

Return a fired job, it will be locked for an amount of time. During this time the worker will run the job and then call dequeue(). If worker crashes, the job will fire on another worker after lock period.

Parameters
connection
lock_forlock delay, by default 1 min
Returns
An object id or an empty string if none found

The documentation for this class was generated from the following files: