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>
|
| 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...
|
|
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.
scheduler::scheduler |
( |
const std::string & |
queue_name | ) |
|
Scheduler constructor.
- Parameters
-
queue_name | redis key used to store jobs, in a ZSET |
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
-
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
-
connection | a valid redis connection |
object_id | an object id, can be everything, like a reference to an Redis hash |
time | absolute 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
-
connection | a valid redis connection |
object_id | an object id, can be everything, like a reference to an Redis hash |
delay | Job 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
-
void scheduler::enqueue |
( |
connection::ptr_t |
connection, |
|
|
const std::string & |
object_id, |
|
|
const boost::posix_time::ptime & |
time |
|
) |
| |
Put a job in schedule.
- Parameters
-
connection | a valid redis connection |
object_id | an object id, can be everything, like a reference to an Redis hash |
time | absolute 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
-
connection | a valid redis connection |
object_id | an object id, can be everything, like a reference to an Redis hash |
delay | Job 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_for | lock 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:
- include/redis3m/patterns/scheduler.h
- src/patterns/scheduler.cpp