You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To trigger the execution of callbacks, one must call `oryx::chron::Scheduler::Tick` at least once a second to prevent missing schedules:
34
+
35
+
```cpp
36
+
for(;;)
37
+
{
38
+
scheduler.Tick();
39
+
std::this_thread::sleep_for(1s);
40
+
}
41
+
```
42
+
43
+
In case there is a lot of time between you call `AddSchedule` and `Tick`, you can call `RecalculateSchedule`.
44
+
45
+
`oryx::chron::Taskinformation` offers a convenient API to retrieve further information:
46
+
47
+
-`oryx::chron::TaskInformation::GetDelay()` informs about the delay between planned and actual execution of the callback. Hence, it is possible to ensure that a task was executed within a specific tolerance:
std::cout << "The Task was executed too late...\n";
57
+
}
58
+
});
59
+
```
60
+
61
+
### Adding multiple tasks with individual schedules at once
62
+
63
+
oryx::chron::Scheduler::AddSchedule needs to sort the underlying container each time you add a schedule. To improve performance when adding many tasks by only sorting once, there is a convinient way to pass either a `std::map<std::string, std::string>`, a `std::vector<std::pair<std::string, std::string>>`, a `std::vector<std::tuple<std::string, std::string>>` or a `std::unordered_map<std::string, std::string>` to `AddSchedule`, where the first element corresponds to the task name and the second element to the task schedule. Only if all schedules in the container are valid, they will be added to `oryx::chron::Scheduler`. The return type is a `std::tuple<bool, std::string, std::string>`, where the boolean is `true` if the schedules have been added or false otherwise. If the schedules have not been added, the second element in the tuple corresponds to the task-name with the given invalid schedule. If there are multiple invalid schedules in the container, `AddSchedule` will abort at the first invalid element:
auto res = c1.AddSchedule(name_schedule_map, [](auto&) { });
73
+
if (std::get<0>(res) == false)
74
+
{
75
+
std::cout << "Task " << std::get<1>(res)
76
+
<< "has an invalid schedule: "
77
+
<< std::get<2>(res) << "\n";
78
+
}
79
+
```
80
+
81
+
82
+
83
+
### Removing schedules from `oryx::chron::Scheduler`
84
+
85
+
`oryx::chron::Scheduler` offers two convenient functions to remove schedules:
86
+
87
+
- `ClearSchedules()` will remove all schedules
88
+
- `RemoveSchedule(std::string)` will remove a specific schedule
89
+
90
+
For example, `scheduler.RemoveSchedule("Hello from Cron")` will remove the previously added task.
91
+
92
+
93
+
94
+
### ThreadSafe Scheduler
95
+
96
+
The scheduler by default is not thread safe if you need a thread safe Scheduler use `MTScheduler`. Alternatively you can also just drop in your own mutex like object. It just needs to satisfy
0 commit comments