Giter Club home page Giter Club logo

scheduler's People

Contributors

bosma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scheduler's Issues

Unsupported cron string leads to unhandled exception

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.

compile error

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();

Race condition

It seems that there is a race condition between here and here. In line 67, tasks is accessed without a lock.

Support proper cron expressions

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!

cron runs at random time

s.cron(15 8 * * *) , this shoud run daily at 8:15am in the morning however it triggers the cron at random time including 8:15 am also

Crash on manage_task while program end and Scheduler destructor called

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.

Passing arguments to schedules

Hello,

Is there a way to pass arguments to the schedules.

I want to do something similar to the following:
for (int i = 0; i < 10; i++)
s.cron("* * * * *", { std::cout << "top of every minute "<< i << std::endl; });

however this will have all the schedules print 9.

at method run at the begin of execution.

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

UTC time support in cron/ccron

Currently all cron/ccron jobs run as per local time. Could you consider an API for adding jobs (cron/ccron) in UTC time ? (1).

'now' method

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 =)

threads do not close ?

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 ?

Error when compiling in Visual Studio Community 2019 16.8.4

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 :)

error when using Bosma::Scheduler in the class

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:

  • init threads
  • resize
  • push function
    after that thread pool do destroy selt, so that scheduler do not working. Please solve this problem because now I only use Bosma::Scheduler in the main function, thank in advanced!!!

Disable/remove task

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...

Compiling

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?

Initialize scheduler in class

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 ?

Callback not triggering from the DLL

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!

Time Drift using every

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.