views:

51

answers:

2

I'm using a Observer on my classes. 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...

+2  A: 

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.

Tim Harper
+1  A: 

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.

qrush