bosma / scheduler Goto Github PK
View Code? Open in Web Editor NEWModern C++ Scheduling Library
License: MIT License
Modern C++ Scheduling Library
License: MIT License
cronScheduler.cron("*/5 * * * *", []() { Foo(); });
This leads to an "invalid stoi argument" exception, at least on MSVC 15.6. I think it's the responsability of the library to gracefully handle incorrect or unsupported arguments for its functions.
c++ example.cpp -o example -std=c++11
get an error and dont know why?!:(
Scheduler.h: In function ‘bool Bosma::try_parse(tm&, const string&, const string&)’:
Scheduler.h:59:22: error: ‘get_time’ is not a member of ‘std’
return !(ss >> std::get_time(&tm, format.c_str())).fail();
It would be amazing if more complex cron expressions could be supported:
cron("*/5 * * * *", []() { std::cout << "every 5 min" << std::endl; });
I see that you have a branch with a C library. I have another suggestion:
https://github.com/mariusbancila/croncpp
C++17 and header only.
I love how simple this library is, with that addition it would be even better. Keep up the good work!
I just tried your example.cpp and modified the sleep time from 10 minutes to 10 seconds in main thread.
That made my program crash on manage_task method while program ended.
I use std::cerr to show the execute order, then I found that destructor called and manage_task called after destructor.
That made program crashed.
I'm using VS2017 to build program.
Please check this problem.
Thanks.
Hi,
Is it normal behavior that the function called like for instance:
s.at("2018-02-27 15:39:30", { std::cout << "at a specific time. RELAY ON" << std::endl; });
will print at a specific time. RELAY ON not only at 2018-02-27 15:39:30 but as well just after program start execution. I my case it seems to be just like that, but I expected to print only on the specified time.
Do you have any hint how to make it working?
I can ensure that my system time is before of the set time in the method call.
BR
Krzysztof
i want to call function from inside function in class, but dont working!
working only on main !
note:scheduling object is inside from member functio of class
Currently all cron/ccron jobs run as per local time. Could you consider an API for adding jobs (cron/ccron) in UTC time ? (1).
When setting a specific time for a cron job, the time has to be in UTC in order for the task to run at the correct time point.
It would be ideal if the time given could be read as local time.
Hi!
Can you add 'now' method for executing some code inside Bosma::Scheduller workers thread pool like this:
template<typename _Callable, typename... _Args> void now(_Callable &&f, _Args &&... args) {
in(std::chrono::nanoseconds(0), std::forward<_Callable>(f), std::forward<_Args>(args)...);
}
This feature in my project help me for free main thread execution using Bosma::Scheduller features.
To your notice =)
I've used your library and task only spawn by number of threads defined at
unsigned int max_n_threads = 2;
so this means only two task would be run and would not run again as if their thread remained open ?
any idea to how to debug this further and fix the problem ?
Hello!!
When compiling in Visual Studio Community 2019 16.8.4, with toolset v142, it throws the next error:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xmemory(230,12): error C2664: 'Bosma::EveryTask::EveryTask(std::chrono::system_clock::duration,std::function<void (void)> &&,bool)': cannot convert argument 2 from '_Ty' to 'std::function<void (void)> &&'
1> with
1> [
1> _Ty=std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xmemory(228,1): message : Reason: cannot convert from '_Ty' to 'std::function<void (void)>'
1> with
1> [
1> _Ty=std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xmemory(230,33): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>E:\Devs\NetworkTonic\Service\NTSupervisor\External libraries\scheduler\Scheduler.h(37,9): message : see declaration of 'Bosma::EveryTask::EveryTask'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\memory(1563): message : see reference to function template instantiation 'void std::_Construct_in_place<_Ty,const std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>>(_Ty &,const std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &> &&) noexcept(false)' being compiled
1> with
1> [
1> _Ty=Bosma::EveryTask
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\memory(2207): message : see reference to function template instantiation 'std::_Ref_count_obj2<_Ty>::_Ref_count_obj2<const std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>>(const std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &> &&)' being compiled
1> with
1> [
1> _Ty=Bosma::EveryTask
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\memory(2208): message : see reference to function template instantiation 'std::_Ref_count_obj2<_Ty>::_Ref_count_obj2<const std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>>(const std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &> &&)' being compiled
1> with
1> [
1> _Ty=Bosma::EveryTask
1> ]
1>E:\Devs\NetworkTonic\Service\NTSupervisor\External libraries\scheduler\Scheduler.h(132): message : see reference to function template instantiation 'std::shared_ptr<Bosma::EveryTask> std::make_shared<Bosma::EveryTask,const std::chrono::system_clock::duration&,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &>>(const std::chrono::system_clock::duration &,std::_Binder<std::_Unforced,void (__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t &,sensorData_t &> &&)' being compiled
1>E:\Devs\NetworkTonic\Service\NTSupervisor\Sources\serviceController.cpp(107): message : see reference to function template instantiation 'void Bosma::Scheduler::every<void(__cdecl &)(const templateData_t &,const sensorData_t &,bool),templateData_t&,sensorData_t&>(const std::chrono::system_clock::duration,_Callable,templateData_t &,sensorData_t &)' being compiled
1> with
1> [
1> _Callable=void (__cdecl &)(const templateData_t &,const sensorData_t &,bool)
1> ]
As far I can understand, there is a problem with std::move. It was working flawlessly with previous version of VS :(
Thank you :)
After change system time to the some moment in the past, Scheduler::every will not work correctly because Clock::now value will change (https://github.com/Bosma/Scheduler/blob/master/Scheduler.h#L182)
because Clock is a std::chrono::system_clock.
I try to using Bosma::Scheduler in my application, I have a TestScheduler define as follow:
`
class TestScheduler : public QWidget
{
Q_OBJECT
public:
TestScheduler(QWidget* parent = 0);
~TestScheduler();
void print();
}
here is it implementation, very simple:
TestScheduler::TestScheduler(QWidget* parent) : QWidget(parent)
{
Bosma::Scheduler s(4);
s.at("2021-05-26 15:50:00", &TestScheduler::print, this);
}
void TestScheduler::print()
{
qDebug() << "ok";
}
`
I run this above but has an error, scheduler do not working. I try to investigate this and found that an error has occupied in the file "ctpl_stl.h", I try print some simple string, the order of thread pool do as follow:
Hello!
Tell me how to disable/remove task, created by interval/every method?
This need to me for stopping execution task without restart sheduller...
For example I may throw spatial exception from body of task, which cancelled schedulling this task in a future...
I cannot get this to compile with either clang or g++, e.g.
Projects/Scheduler/Cron.h:13:41: error: no viable conversion from 'time_point<[...],
duration<[...], ratio<[...], __static_lcm<ratio<1, 1000000>::den, ratio<1, 1000000000>::den>::value aka
1000000000>>>' to 'const time_point<[...], duration<[...], ratio<[...], 1000000>>>'
auto tm_adjusted = Clock::to_time_t(tp + time);
Also, do you have any plans to use make this work with C++11?
Similar to #11 I'd like to use the scheduler inside a method of another class. Say I have Class A
and Class B
where A
calls b.schedule()
(and b is an instance of Class B), with the following code:
public: void schedule(){ Bosma::Scheduler s(12); s.every(std::chrono::milliseconds(100), [](){ // Do something in here } }
In my case, this will execute the code inside the lambda function only once. I already tried getting around this by initializing the Scheduler in-class, like this:
class ClassA(){ public: Bosma::Scheduler s(12); }
but like that compilation fails and states expected identifier before numeric constant
. I also tried other variants of initialization, but since the scheduler object can't be moved or copied, these do not work either.
In the end, I just want to be able to have a modular system, where I do not expose the scheduling to the calling class / function. Is that possible, and if so: how ?
The callback is working in the main function but when I am using Scheduler from DLL the function from the DLL is called perfectly but the callback in the same function is not triggering!
I only want to run the schedule on specific time (let's say 08:00 - 12.00)
and to minimize the CPU usage it would be great to be able to set start and end time
I am using an every call to run a function once a minute. this is to happen exactly on the minute and zero second. It starts out working perfectly, however over time, the execution starts to drift, and executes a second, then 2, then 3... later.
Is there something that can be done to improve the precision of execution ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.