简体   繁体   English

自从Linux服务器计算机启动以来,除非已在命令提示符中执行了railsRunner,否则Rails任务不会运行

[英]Rails task not running unless rails runner has been executed in the command prompt since the linux server machine's bootup

I'm trying to execute this task to update a large amount of data from a controller so that when an administrator user accesses this method it will run the said task. 我正在尝试执行此任务以更新来自控制器的大量数据,以便当管理员用户访问此方法时它将运行所述任务。 I've confirmed that there aren't any issues with the task itself, but I'm not so sure about the way it's being called. 我已经确认任务本身没有任何问题,但是我不确定它的调用方式。

The problem I'm running into is that when I've freshly restarted my virtual machine running the server (using vagrant) the program won't execute. 我遇到的问题是,当我重新启动运行服务器的虚拟机(使用无业游民)时,该程序将无法执行。 But after some testing, I've found that after I run rails runner (the command executed doesn't matter) it will start working. 但是经过一些测试,我发现运行RailsRunner (执行的命令无关紧要)后它将开始工作。

class Admin::AccessLogManageController < Admin::AdminController
  def update_project_ids
    command = "rbenv exec bundle exec rails runner --environment=#{Rails.env} Tasks::UpdateAccessLogProjectIds.execute"
    pid =spawn(command, :chdir=>".")
    Process.detach(pid)
  end
end

I found the problem. 我发现了问题。 It has to do with spring, essentially the environment is set up to try to run with spring, but it doesn't automatically start the processes. 它与spring有关,从本质上说,环境已设置为尝试与spring一起运行,但是它不会自动启动进程。 Adding DISABLE_SPRING=1 seems to fix the issue. 添加DISABLE_SPRING = 1似乎可以解决此问题。

class Admin::AccessLogManageController < Admin::AdminController
  def update_project_ids
    command = "DISABLE_SPRING=1 rbenv exec bundle exec rails runner --environment=#{Rails.env} Tasks::UpdateAccessLogProjectIds.execute"
    pid =spawn(command, :chdir=>".")
    Process.detach(pid)
  end
end

This had the information I needed to solve the problem. 这具有解决问题所需的信息。 Rails runner without spring 没有弹簧的滑轨

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM