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.
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.
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.
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 M.
Chief Technologist
E Factor Media // FN Interactive [email protected]
1-866-263-3261
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 M. wrote:
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.
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,
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.