# Preparing an Asynchronous Response with ActionController

**URL:** <https://www.ruby-forum.com/t/preparing-an-asynchronous-response-with-actioncontroller/185436>\
**Category:** Rails\
**Created:** [March 19, 2010, 10:40pm UTC](https://www.ruby-forum.com/t/preparing-an-asynchronous-response-with-actioncontroller/185436 "2010-03-19T22:40:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 19, 2010, 10:40pm UTC](https://www.ruby-forum.com/t/preparing-an-asynchronous-response-with-actioncontroller/185436/1 "2010-03-19T22:40:22Z")

</div>

Hello,

I was wondering if there’s an easy way to make ActionController render a  
response in an asynchronous background process.

I have a large object graph which takes over a minute to serialize in  
amf:

render :amf =\> myData

I’d like to render() the amf serialization in a workling process and  
store the results in memcache key’d by original msg-id so the client can  
get the serialized result in a subsequent request.

Is there a simple way to perform the render() operation outside the  
context of the controller? Something like:

MyController.new.render({:amf=\>myData})

(of course, render() is a protected method, so I can’t do that. And I’m  
also not sure where to obtain the serialized result since render() is  
void).

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 21, 2010, 9:17am UTC](https://www.ruby-forum.com/t/preparing-an-asynchronous-response-with-actioncontroller/185436/2 "2010-03-21T09:17:54Z")

</div>

Tom Shealy wrote:

> Hello,
> 
> I was wondering if there’s an easy way to make ActionController render a  
> response in an asynchronous background process.
> 
> I have a large object graph which takes over a minute to serialize in  
> amf:
> 
> render :amf =\> myData
> 
> I’d like to render() the amf serialization in a workling process and  
> store the results in memcache key’d by original msg-id so the client can  
> get the serialized result in a subsequent request.
> 
> Is there a simple way to perform the render() operation outside the  
> context of the controller? Something like:
> 
> MyController.new.render({:amf=\>myData})
> 
> (of course, render() is a protected method, so I can’t do that. And I’m  
> also not sure where to obtain the serialized result since render() is  
> void).
> 
> Thanks,
> 
> Tom

For something that takes that long your best bet is to pass it off to  
like Backgroundrb ([http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)) or delayed\_job  
([GitHub - tobi/delayed\_job: Database backed asynchronous priority queue -- Extracted from Shopify](http://github.com/tobi/delayed_job)) for processing.

I’m pretty sure you could call erb directly if you can’t do it through  
the controller (and it’s the actual render that takes the time):

[http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/)

Cheers  
Luke
