Re: [Cppcms-users] best way for background processes
Brought to you by:
artyom-beilis
From: Lee E. <lee...@gm...> - 2012-04-25 21:17:13
|
I prefer a different approach: use cron or some other mechanism to trigger a request to maintanance URL to the application. and activation of wget or similar application with the proper URL can be done from cron - and will give the CppCMS all the necesary context request and response objects it needs. In addition it will make debugging and running maintanance jobs manually much easier On Wed, Apr 25, 2012 at 11:50 PM, Artyom Beilis <art...@ya...> wrote: > > > > >>> 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/ > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > -- -- lee Lee Elenbaas lee...@gm... |