Search code examples
ruby-on-railsrubyjobssynchronoustask-queue

Ruby/Rails synchronous job manager


hi
i'm going to set up a rails-website where, after some initial user input, some heavy calculations are done (via c-extension to ruby, will use multithreading). as these calculations are going to consume almost all cpu-time (memory too), there should never be more than one calculation running at a time. also i can't use (asynchronous) background jobs (like with delayed job) as rails has to show the results of that calculation and the site should work without javascript.
so i suppose i need a separate process where all rails instances have to queue their calculation requests und wait for the answer (maybe an error message if the queue is full), kind of a synchronous job manager.

does anyone know if there is a gem/plugin with such functionality? (nanite seemed pretty cool to me, but seems to be only asynchronous, so the rails instances would not know when the calculation is finished. is that correct?)
another idea is to write my own using distributed ruby (drb), but why invent the wheel again if it already exists?

any help would be appreciated!

EDIT: because of the tips of zaius i think i will be able to do this asynchronously, so i'm going to try resque.


Solution

  • Ruby has mutexes / semaphores.

    You can use a semaphore to make sure only one resource intensive process is happening at the same time.

    However, the idea of blocking a front end process while other tasks finish doesn't seem right to me. If I was doing this, I would use a background worker, and then use a page (or an iframe) with the refresh meta tag to continuously check on the progress.

    That way, you can use the same code for both javascript enabled and disabled clients. And your web app threads aren't blocking.