Skip to content

ScheduledTasks (aka Cron) for Windows

Tim Garrity edited this page Jun 15, 2019 · 1 revision

If you're trying to run your explorer on Windows, perhaps in a development scenario, you'll want to have your tasks configured to run just like they would on Linux.

Linux configuration

*/1 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js index update > /dev/null 2>&1
*/2 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js market > /dev/null 2>&1
*/5 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/peers.js > /dev/null 2>&1

Windows

In Windows, we obviously do not have crontab available, so we're going to put Scheduled Tasks to work and use a powershell script to do what we need.

Step 1) Create the Powershell script to be used:

sync.ps1

$ErrorActionPreference="SilentlyContinue"
$ErrorActionPreference = "Continue"
cd C:\Path\to\explorer; C:\Path\to\node.exe --stack_size=40000 .\scripts\sync.js index update

Basically this is exactly the same as what we're telling Cron to do in Linux:

  • cd to the explorer.
  • Execute node.exe on scripts\sync.js with the index update agruments

Step 2) Configure the Scheduled Task

The scheduled task can be the complicated part, but we'll do our best.

  • Execute "taskschd.msc" from the start menu or search for "Task Scheduler"
  • Right-click on "Task Scheduler Library" and click on "Create Task..."
  • Give the Task a reasonable name such as "Sync-Index-Update" under the General tab.
  • On the "Triggers" tab, click on "New..."
  • Choose to "On Startup" for the 'Begin the task' option.
  • Check 'Repeat task every:" and type '1 minute'. Also change "for a duration of:" to "Indefinitely"
  • On the "Actions" tab, click on "New..."
  • Choose 'Start a program' for your "Action".
  • For the "Program/script" type "powershell". This will tell it to run Powershell application -- Under 'Arguments (optional)', type the following:
-WindowStyle "Hidden" -NoProfile -Noninteractive -File "C:\Path\To\sync.ps1"
  • Now click OK and your Task is complete. You can start it now, since you haven't triggered a "On Startup" yet, by right-clicking your Task and choosing to "Run" it.