如何将Rake任务作为Windows“计划任务”运行?

时间:2022-03-21 05:23:21

I have a rake task I need to run as a daily job on a Windows XP machine. I discovered the Windows "scheduled tasks" control panel. I'm trying to figure out how to get it to run my Rake task.

我有一个rake任务,我需要在Windows XP机器上作为日常工作运行。我发现了Windows“计划任务”控制面板。我正在试图弄清楚如何让它来运行我的Rake任务。

Two of the fields are "run" (with a browse button) and "start in". I tried to enter rake mycategory:mytask into "run" and my Rails project dir containing the Rake task into "start in". The result was a message saying the task "could not start".

其中两个字段是“运行”(带有浏览按钮)和“开始”。我试图输入rake mycategory:mytask into“run”,我的Rails项目目录包含Rake任务进入“start in”。结果是一条消息说任务“无法启动”。

How can I get set up a Windows "scheduled task" to run a Rake task?

如何设置Windows“计划任务”以运行Rake任务?

3 个解决方案

#1


If you can build a batch file that can execute it properly I would do so, and then you can direct the batch file to run with the task.

如果您可以构建一个可以正确执行它的批处理文件,我会这样做,然后您可以指示批处理文件与该任务一起运行。

Something like this should work:

这样的事情应该有效:

:: Run task every hour
@call rake stats RAILS_ENV="production"

#2


Also, aside from the (correct) batch file advice above, AFAIK, you may need to run the task on an account that has a non-empty password set. Property of Scheduler.

此外,除了上面的(正确的)批处理文件建议AFAIK之外,您可能还需要在具有非空密码集的帐户上运行该任务。调度程序的属性。

#3


Just adding an updated/fleshed out answer for those interested...

只为那些感兴趣的人添加更新/充实的答案...

Create a file called rake.bat - make sure to save with ANSI encoding (the default with Windows Notepad). You can save this file anywhere, but I put it in C:\ror\rake.bat

创建一个名为rake.bat的文件 - 确保使用ANSI编码保存(Windows记事本的默认设置)。您可以将此文件保存在任何位置,但我将其放在C:\ ror \ rake.bat中

rake.bat

@call bundle exec rake %*

Now when you create a scheduled task, you can set it to run the .bat file and the arguments are simply what comes after rake. Set it to run inside the directory of your choice. Run whether or not the user is logged in, but do NOT run with the highest privileges. Screenshots below for clarity; my rake task is namespaced manager, and the task itself is sync:

现在,当您创建计划任务时,可以将其设置为运行.bat文件,参数只是rake之后的内容。将其设置为在您选择的目录中运行。运行用户是否已登录,但不以最高权限运行。屏幕截图如下:我的rake任务是命名空间管理器,任务本身是同步的:

如何将Rake任务作为Windows“计划任务”运行?

如何将Rake任务作为Windows“计划任务”运行?

#1


If you can build a batch file that can execute it properly I would do so, and then you can direct the batch file to run with the task.

如果您可以构建一个可以正确执行它的批处理文件,我会这样做,然后您可以指示批处理文件与该任务一起运行。

Something like this should work:

这样的事情应该有效:

:: Run task every hour
@call rake stats RAILS_ENV="production"

#2


Also, aside from the (correct) batch file advice above, AFAIK, you may need to run the task on an account that has a non-empty password set. Property of Scheduler.

此外,除了上面的(正确的)批处理文件建议AFAIK之外,您可能还需要在具有非空密码集的帐户上运行该任务。调度程序的属性。

#3


Just adding an updated/fleshed out answer for those interested...

只为那些感兴趣的人添加更新/充实的答案...

Create a file called rake.bat - make sure to save with ANSI encoding (the default with Windows Notepad). You can save this file anywhere, but I put it in C:\ror\rake.bat

创建一个名为rake.bat的文件 - 确保使用ANSI编码保存(Windows记事本的默认设置)。您可以将此文件保存在任何位置,但我将其放在C:\ ror \ rake.bat中

rake.bat

@call bundle exec rake %*

Now when you create a scheduled task, you can set it to run the .bat file and the arguments are simply what comes after rake. Set it to run inside the directory of your choice. Run whether or not the user is logged in, but do NOT run with the highest privileges. Screenshots below for clarity; my rake task is namespaced manager, and the task itself is sync:

现在,当您创建计划任务时,可以将其设置为运行.bat文件,参数只是rake之后的内容。将其设置为在您选择的目录中运行。运行用户是否已登录,但不以最高权限运行。屏幕截图如下:我的rake任务是命名空间管理器,任务本身是同步的:

如何将Rake任务作为Windows“计划任务”运行?

如何将Rake任务作为Windows“计划任务”运行?