Best practice for Rails App to run a long task in the background?

后端 未结 14 1505
时光取名叫无心
时光取名叫无心 2020-12-07 20:49

I have a Rails application that unfortunately after a request to a controller, has to do some crunching that takes awhile. What are the best practices in Rails for providin

14条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 21:19

    I recommend using Resque gem with it's resque-status plug-in for your heavy background processes.

    Resque

    Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later.

    Resque-status

    resque-status is an extension to the resque queue system that provides simple trackable jobs.

    Once you run a job on a Resque worker using resque-status extension, you will be able to get info about your ongoing progresses and ability to kill a specific process very easily. See examples:

    status.pct_complete #=> 0
    status.status #=> 'queued'
    status.queued? #=> true
    status.working? #=> false
    status.time #=> Time object        
    status.message #=> "Created at ..."
    

    Also resque and resque-status has a cool web interface to interact with your jobs which is so cool.

提交回复
热议问题