Serverless logo
产品
Tencent Serverless
Tencent CLI
组件模板
Serverless 控制台
产品概览
Serverless Cloud
产品概览
适合所有人的零障碍 serverless 应用开发.
腾讯 Serverless 应用控制台
文档
Tencent Serverless
概览
CLI 命令
云函数开发
组件应用开发
使用指南
适合所有人的零障碍 serverless 应用开发.
腾讯 Serverless 应用控制台
价格
更多
介绍
关于我们
招聘岗位
联系我们
支持
专家支持
社区
讨论区
Serverless 全球官网
腾讯 Serverless 中文网
学习
博客教程
代码示例
SCF 指南
腾讯云 SCF 文档
适合所有人的零障碍 serverless 应用开发.
腾讯 Serverless 应用控制台
联系我们应用控制台
Serverless logo
Log in
产品
Tencent Serverless
Serverless CLI
组件模板
Serverless 控制台
产品概览
Serverless Cloud
产品概览
文档
Tencent Serverless
概览
CLI 命令
云函数开发
组件应用开发
使用指南
价格
更多
介绍
关于我们
招聘岗位
联系我们
支持
专家支持
社区
讨论区
Serverless 中文网
学习
博客教程
代码示例
SCF 指南
支持
应用控制台
Serverless logo
Product
Expand
Option 1Option 2Option 3
DocsPricing
Company
Expand
Feature 1
Lorem ipsum dolor emet sin dor lorem ipsum
Feature 2
Lorem ipsum dolor emet sin dor lorem ipsum
Feature 3
Lorem ipsum dolor emet sin dor lorem ipsum
Feature 4
Lorem ipsum dolor emet sin dor lorem ipsum
Search
Sales & Support
LoginSign Up
Open MenuClose Menu
Serverless Cloud - Docs

Serverless Cloud – Documentation

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Item title

Item description

X
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Item title

Item description

Serverless logo
Product
Expand
Option 1Option 2Option 3
DocsPricing
Company
Expand

Feature 1

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 2

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 3

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 4

Lorem ipsum dolor emet sin dor lorem ipsum
Search
Sales & Support
LoginSign Up
Open MenuClose Menu
Get early access
Go to Github
Home
How it Works
Development Workflows
Building Applications
Link 1Link 1Link 1
Building Applications
Link 1Link 1Link 1
Building Applications
Link 1Link 1Link 1
Automated Testing
CLI Reference

Scheduling Tasks

Serverless Cloud also supports scheduled tasks, which you can create using the schedule helper. You can either use the .every() method for having tasks repeat on a regular time interval.Or you can use the .cron() method to have more fine-grained control.

Scheduling tasks with .every()

If you know you need a task to repeat every hour, or every 5 days, you can use the .every() method. This method takes two arguments, a rate expression and the function you'd like to run.

For example, the following will log "I run every hour!" every hour:

schedule.every("1 hour", () => {
  // This code block will run every hour!
  console.log("I run every hour!");
});

A rate expression consists of a numeric value and a unit. Valid units are minute, minutes, hour, hours, day and days.

Scheduling tasks with .cron()

If you need more control over your scheduled tasks, you can use the .cron() method. This method also takes two arguments, a cron expression and the function you'd like to run.

For example, the following will log "I run on Tuesdays!" every Tuesday at midnight UTC:

schedule.cron("0 0 * * TUE *", () => {
  // This code block will run at midnight on Tuesdays!
  console.log("I run on Tuesdays!");
});

Cron expressions consist of six fields:

Field Values Wildcards
Minutes 0-59 , - * /
Hours 0-23 , - * /
Day-of-month 1-31 , - * ? / L W
Month 1-12 or JAN-DEC , - * /
Day-of-week 1-7 or SUN-SAT , - * ? L #
Year 1970-2199 , - * /

Wildcards

  • The , (comma) wildcard includes additional values. In the Month field, JAN,FEB,MAR would include January, February, and March.
  • The - (dash) wildcard specifies ranges. In the Day field, 1-15 would include days 1 through 15 of the specified month.
  • The _ (asterisk) wildcard includes all values in the field. In the Hours field, _ would include every hour. You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.
  • The / (forward slash) wildcard specifies increments. In the Minutes field, you could enter 1/10 to specify every tenth minute, starting from the first minute of the hour (for example, the 11th, 21st, and 31st minute, and so on).
  • The ? (question mark) wildcard specifies one or another. In the Day-of-month field you could enter 7 and if you didn't care what day of the week the 7th was, you could enter ? in the Day-of-week field.
  • The L wildcard in the Day-of-month or Day-of-week fields specifies the last day of the month or week.
  • The W wildcard in the Day-of-month field specifies a weekday. In the Day-of-month field, 3W specifies the weekday closest to the third day of the month.
  • The # wildcard in the Day-of-week field specifies a certain instance of the specified day of the week within a month. For example, 3#2 would be the second Tuesday of the month: the 3 refers to Tuesday because it is the third day of each week, and the 2 refers to the second day of that type within the month.
Serverless logo
Product
Expand
Option 1Option 2Option 3
DocsPricing
Company
Expand

Feature 1

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 2

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 3

Lorem ipsum dolor emet sin dor lorem ipsum

Feature 4

Lorem ipsum dolor emet sin dor lorem ipsum
Search
Sales & Support
LoginSign Up
Open MenuClose Menu
Tencent Serverless
Serverless CLI
组件模板
控制台(即将上线)
Serverless 控制台
产品概览
Serverless Cloud
产品概览
文档案例
说明文档SCF 指南参考示例博客教程腾讯云 SCF 文档
交流社区
讨论区Serverless 全球官网腾讯 Serverless 中文网
技术支持
联系我们专家支持
公司介绍
关于我们招聘岗位合作伙伴
订阅我们的每月更新
订阅成功!
抱歉!订阅错误,请尝试其他方式和我们去的联系。
© 2021 Serverless, Inc. All rights reserved.
服务条款隐私政策