rake任务正在跳过长时间运行的shell进程

时间:2013-12-24 21:44:46

标签: ruby rake

我有一个rake任务,每隔5分钟用crontab运行一次。此rake任务必须启动一个长时间运行的后台进程,该进程根据任务输入创建文件。

由于某些原因,长时间的进程没有运行。我正在使用Backticks来运行命令。

有什么想法吗?

rake任务文件

require 'json'

namespace :scrapper do
  path = '/home/ubuntu/users'
  def lockfile
   Rails.root.join('tmp', 'pids', 'leads_task.lock')
  end

  def running!
   `touch #{lockfile}`
  end

  def done!
   `rm #{lockfile}`
  end

  def running?
    File.exists?(lockfile)
  end

 task :get_profile => :environment  do
  unless running?
    running!
    user = User.last
    `/usr/local/bin/casperjs #{path}/scrapper.coffee #{user.id}`
    done!
  end
 end
end

cron语法看起来像这样

*/5 * * * * /bin/bash -l -c 'cd /home/ubuntu/UserProfile && RAILS_ENV=staging bundle exec rake scrapper:get_profile  --silent >> /home/ubuntu/UserProfile/scrapper_cron.output 2>&1'

很少有事情

  1. cron作业正在运行,我看到在删除它时会创建scrapper_cron.out文件。
  2. 当我在shell中键入并执行它时,rake任务正在运行。

1 个答案:

答案 0 :(得分:0)

我的应用中有rake timeout gem,这会给rake任务带来超时错误。因为,cron命令包含silent标志,它正在抑制错误。