开发者

Rails - asynchronous tasks, forked processes, best practices

I'm using a Observer on my cl开发者_如何转开发asses. When one of the records is created/updated I need to notfify another service (via a URL call). What is the best way to do this to avoid slowing down my class? Would using a gem liked delayed_job be overkill?

In my Observer's after_update() / after_create() I just want to launch a thread that calls the URL...


If your notifier is non-thread blocking, you could simply spawn a thread and perform the notification there. That way, your program will continue to run while that thread is waiting on the response.

Of course, you'll want some way to handle failure. You could have it try three times, and if it still fails, write a notification to the log or something.

The best (most reliable) solution would be to use a job queue. That way, if a job fails outright, you can inspect and resubmit the job again.


Definitely use a community supported/accepted gem like delayed_job or resque. It's really not as hard as you think and your app will scale better down the line.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜