Hi
I need to build an ruby on rails application which will call every 1 second to a remote Api url, in order to catch an event that should be occurred in that remote web server
the url is
“remoteservername.com/folder/folder/waitforevents”
once the wanted event is occurred I need to perform some actions and call again to the “remoteservername.com/folder/folder/waitforevents” url.
This should be a continuously task and done without the opening of a browser. It means that this application should start running immediately after my web server is started.
so my question is how can I run a ruby on rails application without opening the browser
just the server
until now I had experience in writing rails applications which started when the browser was opened and some url was invoked.
so I will be glad if you could guide me on this issue
THANKS
You may use
crontogether with./script/rails runner, which can execute any method from your rails application.Since you need to execute some action every second, you may start that
runneronce, and create a loop. You may start it from the cron, save the PID somewhere and later ask the cron to kill given process, OR you may just timeout in your Ruby code, in the loop. A simple example:A cron task may then create a file “stop_the_loop” in known directory, and your task will stop after a second.
In fact, cron may not be necessary in this case. Since you should have only one instance of this script, it would be better to start it manually, and stop it manually. If you want to use cron, you could add a semaphore-like file, which will tell the script that one process is already running (The file should be removed by the ‘ensure’ block).
An example of the cron config:
..and an example with this ‘semaphore’: