polling with delayed_job

后端 未结 6 1884
[愿得一人]
[愿得一人] 2020-12-12 14:39

I have a process which takes generally a few seconds to complete so I\'m trying to use delayed_job to handle it asynchronously. The job itself works fine, my question is ho

6条回答
  •  心在旅途
    2020-12-12 15:00

    I think that the best way would be to use the callbacks available in the delayed_job. These are: :success, :error and :after. so you can put some code in your model with the after:

    class ToBeDelayed
      def perform
        # do something
      end
    
      def after(job)
        # do something
      end
    end
    

    Because if you insist of using the obj.delayed.method, then you'll have to monkey patch Delayed::PerformableMethod and add the after method there. IMHO it's far better than polling for some value which might be even backend specific (ActiveRecord vs. Mongoid, for instance).

提交回复
热议问题