Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create resque queues on the fly

I am creating a postgres multi-tenant environment. So client A has schema_1, B has schema_2 ect..

Now I don't know all the clients I'll have, so I've got a simple little rake task to create a new schema based on data in a Tenant table.. All perfectly dynamic: To add a new client, add a new tenant, and do a rake tenant:db:migrate.. tada all the tables are there and the client has their own little world. (Unknown cust list, but small so rake at signup is not an issue)

All good...
Except for background jobs.
I want to have a different Queue for each client.

http://blog.kabisa.nl/2010/03/16/dynamic-queue-assignment-for-resque-jobs/ still uses hard coded queues. It can pick between two you knew about when you wrote the code, but they're still not really dynamic.. Not really.

So my question is. I have a string "tenant_1" describing my clients world.
How can I use that string to create a queue that contains jobs only for "him".
How can I create real dynamic queues?

like image 762
baash05 Avatar asked Mar 08 '12 23:03

baash05


2 Answers

Incase anyone comes across this question like I did, I found an answer inside the source.

Resque version 1.x (stable) lists this in /lib/resque.rb, and looks like a better method to call than directly accessing the Job module inside Resque.

 # This method is considered part of the `stable` API.
  def enqueue_to(queue, klass, *args)

Use as such, works flawlessly for me.

Resque.enqueue_to(:my_queue, MyWorker, :my_argument)
like image 54
Ben Patterson Avatar answered Sep 30 '22 03:09

Ben Patterson


Resque::Job.create("client#{client_id}", MyWorker, 3);

This works for us.

like image 35
baash05 Avatar answered Sep 30 '22 03:09

baash05