How to get result from delayed_job like PDF / HTML report

I feel like this is a stupid question because everyone seems to be silent about this aspect of things.

My need is simple - I am running some reports using Ruport on Heroku. Complex reports take a long time and they time out. I decided to use delayed_job, but I could use something else instead. Once I know what I am doing, I can use it for other things as well.

I see many examples, railscasts, documentation on how to run delayed_job and its siblings, how to manage your job queue, etc. I may have questions as soon as I get to this point, but for now ...

How do I get back to my work in line?

Right now, I am just generating output like this:

@report_output     = @report_controller.render(@report_format,@report_params)
send_data @report_output, :filename => "#{@report_type}.#{@report_format}", :type => "application/#{@report_format}" unless :html == @report_format

      

(and then if it's a html report it just renders the page as usual)

it works great in development, time in production. I can see from the documentation that it would be simple to just generate the output and send it to the user, then I don't have to worry about returning the job.

But I don’t want that. I just want to show the user a progress page, try the server regularly until it's done, then redirect them to see the HTML or PDF output. I expect this to return some sort of job id and pass it on to the user so he can check it, but I can't see where this is coming from. I suppose I could just look at the table, but that seems silly. I could even show the user a list of queued jobs / completed jobs and let them pick one manually, but that's overkill. They just want to download the report, and they don't mind if it takes a minute or two.

I am not using a table for my reports, not needed, they are not saved - but I suppose it might give them an ActiveRecord table and model if that helps. It seems I shouldn't have done this. I am using Rails 2.3, but that doesn't sound like my question either.

It seems like I'm asking, so obviously no one bothered to write it down, but I can't find it. Have a sample app? What am I missing? I feel stupid.

+3


source to share


2 answers


You can use a background processing service like IronWorker (disclaimer: I work for Iron.io). You must submit the job to IronWorker and update the worker status while the worker is processing the job in the background. You can then poll IronWorker to show the status to the user and when they have finished refreshing the page. You can also use callbacks from the worker to synchronize between the worker and the application. Glad to help with that.



+1


source


where do you store the output of the horn generation? if you put it somewhere on disk, for example, in S3 storage, you can pre-create a name for your report and transfer it to the client. than you can poll the S3 store if the file is present and then transfer it to the client after the creation is complete.

EDIT



it looks like you are returning the job id when you queue it: poll with job_delay

0


source







All Articles