Feature/add executed on time check (#7)

* Initial commit on executed on time feature. A task was executed on time if the function call happened within one second since it expired.

* Adding tests, fixing some errors.

* Using recursirve mutex to allowing to call safely call was_executed_on_time in an Mt-environment

* Changing from boolean expression to get_delay, being even more flexibel

* Cleanup

* Adding dedicated TaskContext

* Changing to Interface-Class Approach

* Renaming to TaskInformation, making it pure virtual

* Removing unnecessary Proxy-Class

* Cleaning up

* Passing a const reference instead of a pointer to avoid nullptr checks in the callback

* Cleaning up add_schedule.

* Adding TaskInformation API to readme.

Co-authored-by: Heinz-Peter Liechtenecker <h.liechtenecker@fh-kaernten.at>
This commit is contained in:
Heinz-Peter Liechtenecker
2020-09-10 19:03:50 +02:00
committed by GitHub
parent 76da315c13
commit 7ef39558a1
9 changed files with 113 additions and 33 deletions

View File

@ -8,7 +8,7 @@ Libcron offers an easy to use API to add callbacks with corresponding cron-forma
```
libcron::Cron cron;
cron.add_schedule("Hello from Cron", "* * * * * ?", [=]() {
cron.add_schedule("Hello from Cron", "* * * * * ?", [=](auto&) {
std::cout << "Hello from libcron!" std::endl;
});
```
@ -23,6 +23,28 @@ while(true)
}
```
The callback must have the following signature:
```
std::function<void(const libcron::TaskInformation&)>
```
`libcron::Taskinformation` offers a convenient API to retrieve further information:
- `libcron::TaskInformation::get_delay` 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:
```
libcron::Cron cron;
cron.add_schedule("Hello from Cron", "* * * * * ?", [=](auto& i) {
using namespace std::chrono_literals;
if (i.get_delay() >= 1s)
{
std::cout << "The Task was executed too late..." << std::endl;
}
});
```
## Removing schedules from `libcron::Cron`