@@ -8,8 +8,10 @@ This library is completely based on [libcron](https://github.com/PerMalmberg/lib
88
99- Proper CMake support
1010- date lib replaced with std::chrono implementation
11- - Time zone clock
11+ - Time zone clock ` TzClock `
1212- Automated tests for (clang, gcc, msvc)
13+ - Correct Thread Safety Guarantees
14+ - Optional Cron Expression Caching
1315
1416## Third party libraries
1517
@@ -30,7 +32,7 @@ using namespace std::chrono_literals;
3032auto main() -> int {
3133 oryx::chron::Scheduler scheduler;
3234
33- scheduler.AddSchedule("Task-1", "* * * * * ?", [](auto& ) { std::cout << "Hello World \n"; });
35+ scheduler.AddSchedule("Task-1", "* * * * * ?", [](auto info ) { std::cout << info.name << " called with delay" << task.delay << " \n"; });
3436 for (;;) {
3537 scheduler.Tick();
3638 std::this_thread::sleep_for(1s);
@@ -40,11 +42,7 @@ auto main() -> int {
4042}
4143```
4244
43- In order to trigger execution of callbacks one must call ` oryx::chron::Scheduler::Tick ` at least once a second to prevent missing schedules.
44-
45- In case there is a lot of time between you call ` AddSchedule ` and ` Tick ` , you can call ` RecalculateSchedule ` .
46-
47- ` oryx::chron::Taskinformation ` offers a convenient API to retrieve further information:
45+ In order to trigger execution of callbacks one must call ` oryx::chron::Scheduler::Tick ` at least once a second to prevent missing schedules:
4846
4947``` cpp
5048#include < thread>
@@ -58,9 +56,9 @@ using namespace std::chrono_literals;
5856auto main() -> int {
5957 oryx::chron::Scheduler scheduler;
6058
61- scheduler.AddSchedule("Task-1", "* * * * * ?", [](const oryx::chron::TaskInformation& task_info ) {
62- if (task_info.GetDelay() >= 1s) {
63- std::cout << task_info.GetName() << ": my scheduler is ticking to slow\n";
59+ scheduler.AddSchedule("Task-1", "* * * * * ?", [](const oryx::chron::TaskInfo& info ) {
60+ if (info.delay >= 1s) {
61+ std::cout << info.name << ": my scheduler is ticking to slow\n";
6462 }
6563 });
6664 for (;;) {
@@ -72,64 +70,9 @@ auto main() -> int {
7270}
7371```
7472
75- ### Adding multiple tasks with individual schedules at once
76-
77- Add schedule needs to sort the underlying container each time you add a schedule. To improve performance when adding a batch of tasks by only sorting once you can also call AddSchedule with:
78-
79- - ` std::map<std::string, std::string> `
80- - ` std::vector<std::pair<std::string, std::string>> `
81- - ` std::vector<std::tuple<std::string, std::string>> `
82- - ` std::unordered_map<std::string, std::string> `
83-
84- 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
85-
86- ``` cpp
87- #include < chrono>
88- #include < thread>
89- #include < iostream>
90- #include < unordered_map>
91-
92- #include < oryx/chron.hpp>
93-
94- using namespace std ::chrono_literals;
95-
96- auto main() -> int {
97- oryx::chron::Scheduler scheduler;
98-
99- std::unordered_map<std::string, std::string> schedules;
100- for (int i = 1; i <= 50; i++) {
101- schedules["Task-" + std::to_string(i)] = "* * * * * ?";
102- }
103-
104- auto res = scheduler.AddSchedule(schedules, [](const oryx::chron::TaskInformation& task_info) {
105- std::cout << task_info.GetName() << ": "
106- << std::chrono::duration_cast<std::chrono::milliseconds>(task_info.GetDelay()) << "\n";
107- });
108-
109- for (;;) {
110- scheduler.Tick();
111- std::this_thread::sleep_for (1s);
112- }
113-
114- return 0;
115- }
116- ```
117-
118- Adding multiple with an invalid schedule:
73+ ### Adding a batch of schedules at once
11974
120- ``` cpp
121- std::unordered_map<std::string, std::string> schedules;
122- for (int i = 1 ; i <= 50 ; i++) {
123- schedules["Task-" + std::to_string(i)] = "* * * * * ?";
124- }
125- schedules[" Task-50" ] = " invalid" ;
126-
127- auto res = scheduler.AddSchedule(
128- schedules, [](const oryx::chron::TaskInformation& task_info) { std::cout << task_info.GetName(); });
129- if (std::get<0>(res) == false) {
130- std::cout << "Task " << std::get<1>(res) << "has an invalid schedule: " << std::get<2>(res) << "\n";
131- }
132- ```
75+ #### TODO
13376
13477
13578
@@ -180,7 +123,7 @@ auto main() -> int {
180123 while (!stop_requested) {
181124 task_name = "Task-" + std::to_string(counter++);
182125 scheduler.AddSchedule(task_name, "* * * * * ?",
183- [](auto& info) { std::cout << info.GetName() << ": Called\n"; });
126+ [](TaskInfo info) { std::cout << info.name << ": Called\n"; });
184127 std::cout << "Scheduled: " << task_name << "\n";
185128 std::this_thread::sleep_for(1s);
186129 }
@@ -233,7 +176,7 @@ auto main() -> int {
233176
234177This implementation supports cron format, as specified below.
235178
236- Each schedule expression conststs of 6 parts, all mandatory. However, if 'day of month' specifies specific days, then 'day of week' is ignored.
179+ Each schedule expression consists of 6 parts, all mandatory. However, if 'day of month' specifies specific days, then 'day of week' is ignored.
237180
238181``` text
239182┌──────────────seconds (0 - 59)
@@ -302,7 +245,7 @@ These special time specification tokens which replace the 5 initial time and dat
302245|Token|Meaning
303246| --- | --- |
304247| @yearly | Run once a year, ie. "0 0 0 1 1 * ".
305- | @annually | Run once a year, ie. "0 0 0 1 1 * "" .
248+ | @annually | Run once a year, ie. "0 0 0 1 1 * ".
306249| @monthly | Run once a month, ie. "0 0 0 1 * * ".
307250| @weekly | Run once a week, ie. "0 0 0 * * 0".
308251| @daily | Run once a day, ie. "0 0 0 * * ?".
0 commit comments