How can I run a loop process on a Heroku instance (Rails 4)? -
i have heroku rails 4 app want run continuously. processing data amazon sqs.
right now, use clock.rb continuously add delayed job run worker. worker set run 10m, finishes. since clock.rb running every 30 seconds, should restart new process pretty quickly.
my procfile is:
myworker: queue=myworker bundle exec rake jobs:work i'm wondering if there way change procfile perhaps, "every instance of myworker should run process while alive. if dies whatever reason, restart , start processing again"
is there way rails 4 , heroku?
there must be... don't know called surely there's name this.
also, once have running, there way "close process every 10m, , restart, clear memory/restart fresh"?
you don't have delayed job or that; have create custom rake task.
for instance, @ work have line in our procfile:
jobs_worker: bundle exec rake poll_jobs
we added file_jobs.rake file in lib/tasks, this:
task poll_jobs: :environment while true puts "polling jobs" filejob.poll_status! sleep 10 end end
we put in sleep 10 replacement task doesn't spin right away. can take out. moment task completes, automatically restarted again. keep in mind if keep restarting often, heroku might mad @ , not spin task right again.
you put timer in there, or 'number of times make around loop' - , exit when timer expires, or number of times you've been through loop greater 'x'.
does make sense?
Comments
Post a Comment