Search code examples
ruby-on-railsherokutwitterdelayed-job

Keep delayed job running on Heroku


I'm connecting to Twitter's streaming API to get a stream of updates to my Rails app, adding them to the db, etc, etc.

What's the best way to do this on Heroku? Right now, I'm using the delayed_job gem - problem is that the job (connecting to the Twitter Streaming API) expires after hours.

Is there a way to make the job run forever, or a better way to do this?

Thanks


Solution

  • I wouldn't make a job "run forever" as that would mean loading the CPU forever too.

    The way this is usually handled is by using a cron job which starts the specific script at specific intervals (every minute, every hour, every few days, etc.).

    Almost every webhost provides an easy interface to setup such cron jobs via their backend (eg: CPanel).

    In case you're running your own server, you probably already know how to configure such jobs. If you don't, you'll have to lookup the individual setup guide which fits the operating system you're running on your server… there's always a way to run "jobs" at specific intervals (even on MS Windows servers — via scheduling).

    And for a more detailed description and better insight into what "cron" is, you might want to check the "cron" article at Wikipedia , which also provides some pretty good examples.