redis3m  1.0.0
 All Classes Functions Variables Enumerations Pages
scheduler.h
1 // Copyright (c) 2014 Luca Marturana. All rights reserved.
2 // Licensed under Apache 2.0, see LICENSE for details
3 
4 #pragma once
5 
6 #include <string>
7 #include <redis3m/patterns/script_exec.h>
8 #include <redis3m/connection.h>
9 #include <boost/date_time/posix_time/ptime.hpp>
10 #include <boost/date_time/posix_time/posix_time_duration.hpp>
11 
12 namespace redis3m
13 {
14 namespace patterns
15 {
16 
23 class scheduler
24 {
25 public:
30  scheduler(const std::string& queue_name);
31 
38  void append_enqueue(connection::ptr_t connection, const std::string& object_id, const boost::posix_time::ptime& time);
39 
46  void append_enqueue(connection::ptr_t connection, const std::string& object_id, const boost::posix_time::time_duration& delay);
47 
54  void enqueue(connection::ptr_t connection, const std::string& object_id, const boost::posix_time::ptime& time);
55 
62  void enqueue(connection::ptr_t connection, const std::string& object_id, const boost::posix_time::time_duration& delay);
63 
70  void append_dequeue(connection::ptr_t connection, const std::string& object_id);
71 
78  void dequeue(connection::ptr_t connection, const std::string& object_id);
79 
88  std::string find_expired(connection::ptr_t connection, const boost::posix_time::time_duration& lock_for=boost::posix_time::seconds(60));
89 
90 private:
91  std::string _queue;
92  static script_exec find_expired_script;
93 };
94 }
95 }
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 fi...
Definition: scheduler.cpp:48
scheduler(const std::string &queue_name)
Scheduler constructor.
Definition: scheduler.cpp:14
The connection class, represent a connection to a Redis server.
Definition: connection.h:27
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...
Definition: scheduler.cpp:59
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...
Definition: scheduler.cpp:53
Helps to run Lua scripts on a Redis instance. It will take care to use EVALSHA to optimize performanc...
Definition: script_exec.h:21
A scheduler pattern, can be useful to manage "jobs" that needs to be run at a given time...
Definition: scheduler.h:23
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. ...
Definition: scheduler.cpp:20
void enqueue(connection::ptr_t connection, const std::string &object_id, const boost::posix_time::ptime &time)
Put a job in schedule.
Definition: scheduler.cpp:34