rails backgroundjob running jobs in parallel?
I'm very happy with By so far, only I have this one issue:
When one process takes 1 or 2 hours to complete, all other jobs in the queue seem to wait for that o开发者_如何学Cne job to finish. Worse still is when uploading to a server which time's out regularly.
My question: is Bj running jobs in parallel or one after another?
Thank you, Damir
BackgroundJob will only allow one worker to run per webserver instance. This is by design to keep things simple. Here is a quote from Bj's README:
If one ignores platform specific details the design of Bj is quite simple: the main Rails application submits jobs to table, stored in the database. The act of submitting triggers exactly one of two things to occur:
1) a new long running background runner to be started
2) an existing background runner to be signaled
The background runner refuses to run two copies of itself for a given hostname/rails_env combination. For example you may only have one background runner processing jobs on localhost in development mode.
The background runner, under normal circumstances, is managed by Bj itself - you need do nothing to start, monitor, or stop it - it just works. However, some people will prefer manage their own background process, see 'External Runner' section below for more on this.
The runner simply processes each job in a highest priority oldest-in fashion, capturing stdout, stderr, exit_status, etc. and storing the information back into the database while logging it's actions. When there are no jobs to run the runner goes to sleep for 42 seconds; however this sleep is interuptable, such as when the runner is signaled that a new job has been submitted so, under normal circumstances there will be zero lag between job submission and job running for an empty queue.
You can learn more on the github page: Here
精彩评论