Re: [Cppcms-users] best way for background processes
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-04-25 20:50:10
|
>>> but if I try to access to the >>> context .... >>> >> >> See, cppcms::http::context is request/response context... Cron job >> does not have any request/response as it is not initiated by >> the client, so you are probably doing something wrong. >> > > Maybe i have to be more specific. I don't want to access the context in > general, i want access to the cache, to rise some triggers. Ok... You had bring up very interesting point and actually the problem in the CppCMS's API. You can't access cache interface without context, however it should be possible to do some actions on the cache itself as it is not 100% binded to request/response. This is some important point to implement and it requires a feature request in the bug tracking system :-) As it seems to be a design flaw I'll try to take a look on it ASAP. As a workaround for you at this point: ------------------------------------- Have you tried to use cache timeouts instead of "cron job" Every object stored in cache may have expiration timeout, it is the best way to invalidate cache by time. > > Just create a event using deadline_timer, > > but where to "start" this event? If I start it within the constructor of > the async event, this would be wrong, wouldn't it? (this is how i get > the px != 0 error) > Take a look on general AIO examples. Best is something like create some object and then access to its memeber function that starts timers. class my_obj { public: my_obj(booster::aio::io_service &s) : timer_(s) {} void async_run() { timer_.async_wait(...) } void on_timeout(...) { timer_.async_wait(...) } private booster::aio::deadline_timer timer_; }; ....... try { cppcms::service srv(argc,argv); // this is your cron job my_obj obj(srv.get_io_service()); obj.async_run(); srv.run(); } >> and submit a job >> to the thread pool or if it is something very short execute it in >> the event loop itself. > >what is very short in your opinion? Any suggestions when to execute it >in the thread pool and when not? Are you doing something blocking or do you do some heavy computations? Go to thread pool, otherwise do it in event loop. Rising a trigger may be quite heavy if it invalidates many values. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ |