代码之家  ›  专栏  ›  技术社区  ›  jpemberthy

延迟的作业处理作业后回调

  •  4
  • jpemberthy  · 技术社区  · 14 年前

    delayed_job 在上面处理任务,例如:

    foo.delay.something

    之后 something Delayed::Backend::ActiveRecord::Job 同学们,但是应该有更干净更好的方法来做这件事。

    3 回复  |  直到 8 年前
        1
  •  3
  •   bkeepers    14 年前

    我会在#foo方法的末尾更新它:

    def foo
      # do work here
      update_attribute :processed, true
    end
    
        2
  •  1
  •   Joe Martinez    14 年前

        3
  •  0
  •   iwasrobbed    13 年前

    Delayed::Job.enqueue InstructionRequestJob.new( p1, p2 )
    
    InstructionRequestJob perform
    - perform a task on a remote server
    - get a response
    - case response
      when OK
        update attribute ( as suggested)
      else
        # how many attempts ?
        if too_many_attempts
           update attribute
           destroy the job
        else
           reschedule the job for another attempt
    - end