开发者

Any way to have delayed_job execute some run-once code at startup and use across all jobs?

So I've got a delayed_job task that pushes some info to an XMPP server. Ideally you create a connection to XMPP once and then constantly push data to it, rather than creating a new connection every time you have some data to send.

Is there any kind of facility in delayed_job for running a sort of 'setup' method when a worker starts, have it set some instance variables (like the XMPP connection object) that can then be used by all the jobs that come up? It's okay if each worker runs its own setup method. I just don't want every job (thousands per day) connecting to the XMPP server from scratch every time.

Thanks for any he开发者_C百科lp!


Delayed Job now has "Hooks" (enqueue, before, after, success, error, failure) - it looks like these were added around June 2010. The before hook would probably work in a case where you wanted to find an existing connection to reuse.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜