How to run a Rake task as a scheduled Windows task?

I have a rake task that I have to run as a daily task on a computer running Windows XP. I found the Windows Scheduled Tasks control panel. I am trying to figure out how to get it to run my Rake task.

Two fields โ€œstartโ€ (with a browse button) and โ€œstartโ€. I tried putting rake mycategory:mytask in "run" and my Rails project project containing the Rake task in "start in". The result was a message that the task "cannot begin."

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

+4
source share
3 answers

If you can create a batch file that can execute it correctly, I would do it, and then you can send a batch file to run with the task.

Something like this should work:

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

In addition to the (correct) advice from the batch file above, AFAIK, you may need to run the task in an account with a non-empty set of passwords. Scheduler property.

+2
source

Just adding an updated / flash answer for those interested ...

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

rake.bat

 @call bundle exec rake %* 

Now that you are creating the scheduled task, you can set it to run the .bat file, and the arguments are just what happens after the rake . Install it to run inside the directory of your choice. Whether logging in but not running with the highest privileges. Screenshots below for clarity; my rake task has a manager namespace, and the sync task itself:

Edit Action Dialog Box

Edit Task Dialog Box

+1
source

Source: https://habr.com/ru/post/1286495/


All Articles