Hello, Is it possible to trigger an action in a controller when a table from database changes? I thought about using an utility like cron (railscron) to check every, e.g. 2 s, if the table changed, but I am wondering if there is a solution a bit more ''elegant'': to trigger an action exactly when the change is made. Best regards, -- Kuba Nowak
On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote:> Hello, > > Is it possible to trigger an action in a controller when > a table from database changes? > I thought about using an utility like cron (railscron) to > check every, e.g. 2 s, if the table changed, but I am wondering > if there is a solution a bit more ''elegant'': to trigger an action > exactly when the change is made. > > Best regards, > -- > Kuba Nowak > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >You could use the after_save callback, along with the ruby http library, to ping the controller. -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261
Kyle Maxwell <kyle@kylemaxwell.com> wrote:> On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > > Is it possible to trigger an action in a controller when > > a table from database changes? > > I thought about using an utility like cron (railscron) to > > check every, e.g. 2 s, if the table changed, but I am wondering > > if there is a solution a bit more ''elegant'': to trigger an action > > exactly when the change is made. > > You could use the after_save callback, along with the ruby http > library, to ping the controller.I have two independent application (Rails app and C++ app) which change the same table (but diffrent columns) in a database. The scenario is following: Rails app populates a table with some data to check and leaves the column ''checked_at'' null. Next C++ app checks this data and mark its activity by setting the column ''checked_at'' at the proper time. The results goes to new row in another table which "belongs" to Rails app, it means, it''s mapped to Rails class. I don''t know if this idea is correct, but I would like to know how to find out when C++ app makes its work in order to take a glance (in Rails app) at the results. Any help, any ideas will be (very :)) apprecieted. -- Kuba Nowak
On 2/15/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote:> Kyle Maxwell <kyle@kylemaxwell.com> wrote: > > On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > > > Is it possible to trigger an action in a controller when > > > a table from database changes? > > > I thought about using an utility like cron (railscron) to > > > check every, e.g. 2 s, if the table changed, but I am wondering > > > if there is a solution a bit more ''elegant'': to trigger an action > > > exactly when the change is made. > > > > You could use the after_save callback, along with the ruby http > > library, to ping the controller. > > I have two independent application (Rails app and C++ app) which > change the same table (but diffrent columns) in a database. The > scenario is following: Rails app populates a table with some data to > check and leaves the column ''checked_at'' null. Next C++ app checks > this data and mark its activity by setting the column ''checked_at'' at > the proper time. The results goes to new row in another table which > "belongs" to Rails app, it means, it''s mapped to Rails class. > > I don''t know if this idea is correct, but I would like to know how to > find out when C++ app makes its work in order to take a glance (in > Rails app) at the results. > > Any help, any ideas will be (very :)) apprecieted. > > -- > Kuba Nowak > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >C++ system command executes curl/short ruby script that pings the action? -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261
Kyle beat me to the curl suggestion :) However, after further thought, I''m wondering why you need all this complexity? The only reason I can see why you''d need to have the Rails app check the db every few seconds is because you are caching something. I would simply have the Rails app grab the data directly from the DB upon every request and recompute your values. Only in slow Java applications have I found caching very useful... On Wednesday, February 15, 2006, at 2:37 PM, Kyle Maxwell wrote:>On 2/15/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: >> Kyle Maxwell <kyle@kylemaxwell.com> wrote: >> > On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: >> > > Is it possible to trigger an action in a controller when >> > > a table from database changes? >> > > I thought about using an utility like cron (railscron) to >> > > check every, e.g. 2 s, if the table changed, but I am wondering >> > > if there is a solution a bit more ''elegant'': to trigger an action >> > > exactly when the change is made. >> > >> > You could use the after_save callback, along with the ruby http >> > library, to ping the controller. >> >> I have two independent application (Rails app and C++ app) which >> change the same table (but diffrent columns) in a database. The >> scenario is following: Rails app populates a table with some data to >> check and leaves the column ''checked_at'' null. Next C++ app checks >> this data and mark its activity by setting the column ''checked_at'' at >> the proper time. The results goes to new row in another table which >> "belongs" to Rails app, it means, it''s mapped to Rails class. >> >> I don''t know if this idea is correct, but I would like to know how to >> find out when C++ app makes its work in order to take a glance (in >> Rails app) at the results. >> >> Any help, any ideas will be (very :)) apprecieted. >> >> -- >> Kuba Nowak >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > >C++ system command executes curl/short ruby script that pings the action? > >-- >Kyle Maxwell >Chief Technologist >E Factor Media // FN Interactive >kyle@efactormedia.com >1-866-263-3261 > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails >Cheers! --Dave Teare http://devlists.com - Email list management http://palmsphere.com - Apps for your hand-held -- Posted with http://DevLists.com. Sign up and save your time!
Dave Teare <devlists-rubyonrails@devlists.com> wrote:> However, after further thought, I''m wondering why you need all this > complexity? The only reason I can see why you''d need to have the Rails > app check the db every few seconds is because you are caching something.Each user of my application can send a task (a request) for which the calculating time may vary from one up to several minutes. So it''s obvious that I''m forced to make him wait. But I don''t want to. I think that if I used a rails app to submit tasks and another app to give the response I would need a trick to notify a user that his task was calculated. That''s the reason I wanted to check the state of database to find out which tasks of which users are finished. Maybe should I use a queuing system or something like that? Performance is the issue. I will have about 2000 users, and wait for demands of about 100 users at once. Best regards,> I would simply have the Rails app grab the data directly from the DB > upon every request and recompute your values. Only in slow Java > applications have I found caching very useful... > > On Wednesday, February 15, 2006, at 2:37 PM, Kyle Maxwell wrote: > >On 2/15/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > >> Kyle Maxwell <kyle@kylemaxwell.com> wrote: > >> > On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > >> > > Is it possible to trigger an action in a controller when > >> > > a table from database changes? > >> > > I thought about using an utility like cron (railscron) to > >> > > check every, e.g. 2 s, if the table changed, but I am wondering > >> > > if there is a solution a bit more ''elegant'': to trigger an action > >> > > exactly when the change is made. > >> > > >> > You could use the after_save callback, along with the ruby http > >> > library, to ping the controller. > >> > >> I have two independent application (Rails app and C++ app) which > >> change the same table (but diffrent columns) in a database. The > >> scenario is following: Rails app populates a table with some data to > >> check and leaves the column ''checked_at'' null. Next C++ app checks > >> this data and mark its activity by setting the column ''checked_at'' at > >> the proper time. The results goes to new row in another table which > >> "belongs" to Rails app, it means, it''s mapped to Rails class. > >> > >> I don''t know if this idea is correct, but I would like to know how to > >> find out when C++ app makes its work in order to take a glance (in > >> Rails app) at the results. > >> > >> Any help, any ideas will be (very :)) apprecieted. > >> > >> -- > >> Kuba Nowak > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > >C++ system command executes curl/short ruby script that pings the action? > > > >-- > >Kyle Maxwell > >Chief Technologist > >E Factor Media // FN Interactive > >kyle@efactormedia.com > >1-866-263-3261 > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > Cheers! > --Dave Teare > http://devlists.com - Email list management > http://palmsphere.com - Apps for your hand-held > > > -- > Posted with http://DevLists.com. Sign up and save your time! > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Kuba Nowak
On 2/16/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote:> Dave Teare <devlists-rubyonrails@devlists.com> wrote: > > However, after further thought, I''m wondering why you need all this > > complexity? The only reason I can see why you''d need to have the Rails > > app check the db every few seconds is because you are caching something. > > Each user of my application can send a task (a request) for which the > calculating time may vary from one up to several minutes. So it''s > obvious that I''m forced to make him wait. But I don''t want to. I think > that if I used a rails app to submit tasks and another app to give the > response I would need a trick to notify a user that his task was > calculated. That''s the reason I wanted to check the state of database > to find out which tasks of which users are finished. > > Maybe should I use a queuing system or something like that? > > Performance is the issue. I will have about 2000 users, and wait for > demands of about 100 users at once. > > Best regards, > > > I would simply have the Rails app grab the data directly from the DB > > upon every request and recompute your values. Only in slow Java > > applications have I found caching very useful... > > > > On Wednesday, February 15, 2006, at 2:37 PM, Kyle Maxwell wrote: > > >On 2/15/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > > >> Kyle Maxwell <kyle@kylemaxwell.com> wrote: > > >> > On 2/14/06, Jakub Nowak <jnowak@wmid.amu.edu.pl> wrote: > > >> > > Is it possible to trigger an action in a controller when > > >> > > a table from database changes? > > >> > > I thought about using an utility like cron (railscron) to > > >> > > check every, e.g. 2 s, if the table changed, but I am wondering > > >> > > if there is a solution a bit more ''elegant'': to trigger an action > > >> > > exactly when the change is made. > > >> > > > >> > You could use the after_save callback, along with the ruby http > > >> > library, to ping the controller. > > >> > > >> I have two independent application (Rails app and C++ app) which > > >> change the same table (but diffrent columns) in a database. The > > >> scenario is following: Rails app populates a table with some data to > > >> check and leaves the column ''checked_at'' null. Next C++ app checks > > >> this data and mark its activity by setting the column ''checked_at'' at > > >> the proper time. The results goes to new row in another table which > > >> "belongs" to Rails app, it means, it''s mapped to Rails class. > > >> > > >> I don''t know if this idea is correct, but I would like to know how to > > >> find out when C++ app makes its work in order to take a glance (in > > >> Rails app) at the results. > > >> > > >> Any help, any ideas will be (very :)) apprecieted. > > >> > > >> -- > > >> Kuba Nowak > > >> _______________________________________________ > > >> Rails mailing list > > >> Rails@lists.rubyonrails.org > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > >> > > > > > >C++ system command executes curl/short ruby script that pings the action? > > > > > >-- > > >Kyle Maxwell > > >Chief Technologist > > >E Factor Media // FN Interactive > > >kyle@efactormedia.com > > >1-866-263-3261 > > > > > >_______________________________________________ > > >Rails mailing list > > >Rails@lists.rubyonrails.org > > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > Cheers! > > --Dave Teare > > http://devlists.com - Email list management > > http://palmsphere.com - Apps for your hand-held > > > > > > -- > > Posted with http://DevLists.com. Sign up and save your time! > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > -- > Kuba Nowak > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Look at this article for an example of running a queue with RailsCron: http://kylemaxwell.com/articles/2006/01/26/simple-emailqueue-for-rails For something like this, I prefer to send the user an email informing him/her that the task is complete. O''Reilly Safari also sends emails in similar situations. -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261
The approach I would take is to have the the task processor have a "completion" flag/timestamp in the database, and corresponding "has_been_read" flag/timestamp, or something along those lines. Any time the user requests a page in the app, check to see if there are any completed, unread notices and use the :flash to notify them somewhere in the layout. Think along the lines of a "New Mail" alert on a portal or webmail service. If you want something more proactively pushed out, maybe because the app window gets left open idle for long periods after task submission, maybe have a div in your layout reserved for that sort of notice and have a periodically_call_remote() check for newly completed jobs and put an elert in the div. Use it sparingly, though, to save the server from thousands of status checks a minute. Maybe only bring it into play in a view when the user has a pending submitted task. -sk Jakub Nowak wrote:> Dave Teare <devlists-rubyonrails@devlists.com> wrote: >> However, after further thought, I''m wondering why you need all this >> complexity? The only reason I can see why you''d need to have the Rails >> app check the db every few seconds is because you are caching something. > > Each user of my application can send a task (a request) for which the > calculating time may vary from one up to several minutes. So it''s > obvious that I''m forced to make him wait. But I don''t want to. I think > that if I used a rails app to submit tasks and another app to give the > response I would need a trick to notify a user that his task was > calculated. That''s the reason I wanted to check the state of database > to find out which tasks of which users are finished. > > Maybe should I use a queuing system or something like that? > > Performance is the issue. I will have about 2000 users, and wait for > demands of about 100 users at once. > > Best regards,-- Posted via http://www.ruby-forum.com/.