delayed_job not logging

后端 未结 4 1262
轻奢々
轻奢々 2020-12-18 02:07

I cannot log messages from my delayed_job process. Here is the job that is being run.

class MyJob
  def initialize(blahblah)
    @blahblah = blahblah
    @lo         


        
4条回答
  •  一个人的身影
    2020-12-18 02:19

    An explation could be that the job gets initialized only once on producer side. Then it gets serialized, delivered through the queue (database for example) and unserialized in the worker. But the initialize method is not being called in the worker process again. Only the perform method is called via send.

    However you can reuse the workers logger to write to the log file:

    class MyJob
      def perform
        say "performing like hell"
      end
    
      def say(text)
        Delayed::Worker.logger.add(Logger::INFO, text)
      end
    end
    

    Don't forget to restart the workers.

提交回复
热议问题