delayed_job: max_run_time 一定不要设定过短 ( max_run_time should be shorter than any kind of job )

访问量: 1461

今天被这个问题搞死了。 ( I am almost beaten by this issue today) 

有两种JOB: 一种是父JOB, 专门生成子job. 一种是 "子job"  ( I have 2 kinds of job: spawner job which generates normal jobs, normal job)

前者 耗时比较久, 5分钟左右, 后者3秒以内。 ( the spawner lasts minutes, and normal jobs last less than 3 seconds) 

今天发现的问题是:  父JOB正常来说应该只运行一次,结果发现它会运行2~3次不等。 ( today I found that spawner job always run more than I time) 

弄了3个小时以后才发现问题:  配置 中的 max_run_time 太短了,导致每次delayed_job 都以为正常运行的父JOB失败了呢。结果第二个WORKER就开始工作了。。。 ( after 3 hours I found the root cause: I set max_run_time too short ( 1 minute ))

  ( 看到了吗? 每次都差1分钟)
sg552@youku:/sg552/workspace/m-cms-static-page-generator/log$ grep 'generating' delayed_job_2014-05-18.log 
16:42:25 INFO: == a plan is generating 1512 files/jobs 
16:43:26 INFO: == a plan is generating 1512 files/jobs 

解决办法: 增加 max_run_time, 让它不短于任何一种job:   ( solution is: increase the "max_run_time" option to make it longer than any job) 

 (修改 max_run_time )
# -*- encoding : utf-8 -*-
# config/initializers/delayed_job_config.rb
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 10
Delayed::Worker.max_attempts = 5 
Delayed::Worker.max_run_time = 30.minutes  
Delayed::Worker.read_ahead = 10
Delayed::Worker.default_queue_name = 'default'

订阅/RSS Feed

Subscribe

分类/category