Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>SchedulerNew to Visual Studio Code? Get it now.
Scheduler

Scheduler

Techcave

|
2,744 installs
| (1) | Free
VS Code Schedule Extension
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Scheduler

Scheduler 是一个在 Vs Code 中管理项目计划任务的扩展。

使用方法

在项目文件夹下面新建 .vscode/schedule.yaml 文件,例如:

- 
 name: Auto Git
 rule: "'42 1 * * * *'"
 job: |
  if (!sch_g.terminal) {
   sch_g.terminal = vscode.window.createTerminal('test terminal');
  }
  sch_g.terminal.show();
  sch_g.terminal.sendText('git add -A');
  sch_g.terminal.sendText('git commit -m "auto commit by VS Code Extension Scheduler"');
  sch_g.terminal.sendText('git pull');
  sch_g.terminal.sendText('git push');
  sch_g.terminal.dispose();
- 
 name: Job1
 rule: "'*/2 2 * * * *'"
 job: |
  if (!sch_g.testoutput) {
    sch_g.testoutput = vscode.window.createOutputChannel("test msg");
  }
  sch_g.testoutput.show(true);
  sch_g.testoutput.appendLine("this.is out put message 000000000000");
- 
 name: Job2
 rule: "'*/3 2 * * * *'"
 job: |
  if (!sch_g.testoutput) {
    sch_g.testoutput = vscode.window.createOutputChannel("test msg");
  }
  sch_g.testoutput.show(true);
  sch_g.testoutput.appendLine("this.is out put message 22222222222222");
- 
 name: Test Job
 rule: new Date(2022, 1, 28, 10, 30, 0)
 job: vscode.window.showInformationMessage('Hello World from VCExt!')
- 
 name: Cron-style Schedule
 rule: "'*/5 * * * * *'"
 job: |
  console.log('Hello console test')
- 
 name: Date-based Schedule
 rule: new Date(2022, 1, 14, 17, 57, 0)
 job: |
  console.log('Hello console test')
- 
 name: Recurrence Rule Schedule
 rule: |
  const rule = new schedule.RecurrenceRule();
  rule.minute = 2;
  rule;
 job: |
  console.log('Hello console test')
- 
 name: Object Literal Syntax
 rule: {hour: 14, minute: 30, dayOfWeek: 0}
 job: |
  console.log('Hello console test')

通过 yaml 文件配置多组 schedule 任务,其中 rule 定义任务执行的触发条件,job 定义了任务执行的具体内容。

rule 配置规则

rule 规则使用 node-schedule 实现定时任务

Cron-style Scheduling

The cron format consists of:

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

Examples with the cron format:

rule: "'42 * * * *'"

Execute a cron job when the minute is 42 (e.g. 19:42, 20:42, etc.).

And:

rule: "'0 17 ? * 0,4-6'"

Execute a cron job every 5 Minutes = */5 * * * *

Unsupported Cron Features

Currently, W (nearest weekday) and L (last day of month/week) are not supported. Most other features supported by popular cron implementations should work just fine, including # (nth weekday of the month).

[cron-parser] is used to parse crontab instructions.

Date-based Scheduling

Say you very specifically want a function to execute at 5:30am on December 21, 2012. Remember - in JavaScript - 0 - January, 11 - December.

rule: new Date(2012, 11, 21, 5, 30, 0)

Recurrence Rule Scheduling

You can build recurrence rules to specify when a job should recur. For instance, consider this rule, which executes the function every hour at 42 minutes after the hour:

rule: |
 var rule = new schedule.RecurrenceRule();
 rule.minute = 42;
 rule;

You can also use arrays to specify a list of acceptable values, and the Range object to specify a range of start and end values, with an optional step parameter. For instance, this will print a message on Thursday, Friday, Saturday, and Sunday at 5pm:

rule: |
 var rule = new schedule.RecurrenceRule();
 rule.dayOfWeek = [0, new schedule.Range(4, 6)];
 rule.hour = 17;
 rule.minute = 0;
 rule;

Timezones are also supported. Here is an example of executing at the start of every day in the UTC timezone.

rule: |
 var rule = new schedule.RecurrenceRule();
 rule.hour = 0;
 rule.minute = 0;
 rule.tz = 'Etc/UTC';
 rule;

A list of acceptable tz (timezone) values can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

RecurrenceRule properties

  • second (0-59)
  • minute (0-59)
  • hour (0-23)
  • date (1-31)
  • month (0-11)
  • year
  • dayOfWeek (0-6) Starting with Sunday
  • tz

Note: It's worth noting that the default value of a component of a recurrence rule is null (except for second, which is 0 for familiarity with cron). If we did not explicitly set minute to 0 above, the message would have instead been logged at 5:00pm, 5:01pm, 5:02pm, ..., 5:59pm. Probably not what you want.

Object Literal Syntax

To make things a little easier, an object literal syntax is also supported, like in this example which will log a message every Sunday at 2:30pm:

rule: {hour: 14, minute: 30, dayOfWeek: 0}

Set StartTime and EndTime

It will run after 5 seconds and stop after 10 seconds in this example. The ruledat supports the above.

rule: |
 const startTime = new Date(Date.now() + 5000);
 const endTime = new Date(startTime.getTime() + 5000);
 { start: startTime, end: endTime, rule: '*/1 * * * * *' }
  • [[CHANGELOG]]
  • [[README_zh]]
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft