polling with delayed_job

后端 未结 6 1875
[愿得一人]
[愿得一人] 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 14:59

    I'd suggest that if it's important to get notification that the job has completed, then write a custom job object and queue that rather than relying upon the default job that gets queued when you call Available.delay.dosomething. Create an object something like:

    class DoSomethingAvailableJob
    
      attr_accessor options
    
      def initialize(options = {})
        @options = options
      end
    
      def perform
        Available.dosomething(@options)
        # Do some sort of notification here
        # ...
      end
    end
    

    and enqueue it with:

    Delayed::Job.enqueue DoSomethingAvailableJob.new(:var => 1234)
    

提交回复
热议问题