salsa  0.3.0
Job.hh
1 #pragma once
2 
3 #include <Object.hh>
4 #include <TaskInfo.pb.h>
5 #include <json/json.h>
6 namespace Salsa {
15 
16 class Job : public Object {
17 public:
19  enum QueueType { pending, assigned, running, done, failed, all }; // TODO maybe go explicit?
20  Job(std::string uuid = "", std::string type = "NONE");
21  virtual ~Job();
22 
23  void print() const;
24  void json(Json::Value & json);
25 
27  TaskInfo * nextJob(); // I assume task
28 
29  // TODO Annotate task ops
30  void tasks(std::vector<TaskInfo *> & v, QueueType type, bool clear = true);
31  bool addTask(uint32_t id, TaskInfo * pJob, QueueType type);
32  bool moveTask(uint32_t id, QueueType from, QueueType to);
33  bool moveTask(uint32_t id, TaskInfo * pJI, QueueType from, QueueType to);
34  bool removeTask(uint32_t id, QueueType from);
35 
36  // TODO size ops
37  size_t size(QueueType t = all) const;
38  size_t sizeNotFinished() const;
39 
40  // TODO no idea...
41  void consumer(std::string uuid);
42  std::string consumer() const;
43 
44  // TODO no idea #2...
45  void feeder(std::string uuid);
46  std::string feeder() const;
47 
48  // TODO task statuses
49  bool haveMoreTasks() const;
50  void haveMoreTasks(bool hasMoreTasks);
51 
53  bool isTaskInQueue(uint32_t id, QueueType type) const;
54 
55 protected:
56  std::map<uint32_t, TaskInfo *> mTasks[all] = {};
57  std::string mUUID = "";
58  std::string mConsumerUUID = "";
59  std::string mFeederUUID = "";
60  std::string mType = "NONE";
61  bool mHaveMoreTasks = true;
62 };
63 } // namespace Salsa
size_t size(QueueType t=all) const
Definition: Job.cc:160
size_t sizeNotFinished() const
Definition: Job.cc:178
Job(std::string uuid="", std::string type="NONE")
Definition: Job.cc:3
std::string mFeederUUID
Feeder UUID.
Definition: Job.hh:59
bool isTaskInQueue(uint32_t id, QueueType type) const
Check task presence in certain queue.
Definition: Job.cc:119
Job class
Definition: Job.hh:16
void tasks(std::vector< TaskInfo *> &v, QueueType type, bool clear=true)
Definition: Job.cc:105
std::string mConsumerUUID
Source (consumer) UUID.
Definition: Job.hh:58
std::string mUUID
Job UUID.
Definition: Job.hh:57
std::map< uint32_t, TaskInfo * > mTasks[all]
Lists of jobs.
Definition: Job.hh:56
virtual ~Job()
Definition: Job.cc:9
Definition: Actor.cc:2
QueueType
Queue types.
Definition: Job.hh:19
bool mHaveMoreTasks
Flag if we have more tasks.
Definition: Job.hh:61
std::string feeder() const
Definition: Job.cc:213
bool haveMoreTasks() const
Definition: Job.cc:221
void json(Json::Value &json)
Definition: Job.cc:144
Base Salsa Object class
Definition: Object.hh:15
std::string consumer() const
Definition: Job.cc:197
bool removeTask(uint32_t id, QueueType from)
Definition: Job.cc:76
std::string mType
Job type.
Definition: Job.hh:60
void print() const
Definition: Job.cc:133
bool moveTask(uint32_t id, QueueType from, QueueType to)
Definition: Job.cc:45
bool addTask(uint32_t id, TaskInfo *pJob, QueueType type)
Definition: Job.cc:25
TaskInfo * nextJob()
TODO Get next available task?job?
Definition: Job.cc:90