Search code examples
ruby-on-railsruby-on-rails-4delayed-job

rails 4 delayed job - Running Delayed Job according to the requested url or domain


I have a requirement in one of the application which deals with the delayed Jobs. I am running two applications using single database.

Here i am facing a problem to call the domain specific delayed Jobs.

For example lets say we are running two applications with domain names abc.com and xyz.com using single database and initiated a delayed job from abc.com and set the time for call a job, as the request from xyz.com is calling milliseconds before the abc.com the job from xyz.com is initiating and job is running with wrong perameters.Here i want a solution by which we can call the delayed job according to the call from the domain or requested url.

Can any one help me in this regard as i was stucked with the possibilities to handle this situations.

Thanks in advance


Solution

  • You could set up two different delayed job queues to handle jobs for each domain separately, rather than having all jobs being placed on one single queue.

    e.g.

    object.delay(:queue => 'domain_one').method
    object.delay(:queue => 'domain_two').method
    

    From here you can then run two separate workers which can service each queue individually.

    https://github.com/collectiveidea/delayed_job has information how to use multiple queues with DelayedJob