SAE平台目前提供用户定制cron服务,用户通过增加项目配置文件config.yaml里的cron字段,来定制自己的cron服务,cron服务支持次数、时区、访问权限等功能支持,并且运行在高可靠SLA的分布式架构上,保证用户的定时服务可靠准确。
用户想添加app的cron,只需编辑项目的config.yaml即可,config在SDK/apps/目录下的用户项目的某个版本的根目录下,没有设置cron的config.yaml格式如下:
name: example version: 1 accesskey: abc
设置了cron服务的config.yaml格式如下:
name: example
version: 1
accesskey: abc
cron:
- description: cron test
url: mycron/test.php
schedule: $2 day of octorber 19:00
timezone: Beijing
- description: another cron test
url: mycron/another_test.php
schedule: every 10 mins
timezone: Beijing
上面就是设置了cron的一个config.yaml的例子,可以看出对example这个项目定制了2个cron服务,分别是代码目录mycron/下的test.php和another_test.php, 校时时区是北京时间,而定时分别是每年10月2号的19:00运行和每10分钟运行。
一些cron定制的例子:
cron:
- description: cron test
url: mycron/test.php
schedule: every 5 mins
login: kobe@123456
运行mycron/test.php,每隔5分钟,基于中国北京时间,http访问权限为用户名kobe、密码123456
cron:
- description: cron test
url: mycron/test.php
schedule: every monday of march 11:00
timezone: Beijing
运行mycron/test.php,每年3月的每个周一的11:00,基于北京时间
cron:
- description: cron test
url: mycron/test.php
schedule: every sunday of month 20:10
timezone: LosAngeles
运行mycron/test.php,每月的每个周日的20:10,基于美国洛杉矶时间
cron:
- description: cron test
url: mycron/test.php
schedule: $2 day of month 19:00
timezone: Moscow
运行mycron/test.php,每月的2号19:00,基于俄罗斯莫斯科时间
SAE cron服务基于高冗余的可靠性定时服务架构,保证99999 SLA,误差时间不超过10秒
username = [a-zA-Z0-9]+
password = [a-zA-Z0-9]+
INT = 0|([1-9]+[0-9]*)
string = [^\n]*
ordinal = $INT
days = 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday' | 'day'
months = 'january' | 'february' | 'march' | 'april' | 'may' | 'june' | 'july' |
'august' | 'september' | 'octorber' | 'november' | 'december' | 'month'
datetime = [0-23]:[0-59]
timezone_expreesion = 'Beijing' | 'NewYork' | 'London' | 'Sydney' | 'Moscow' | 'Berlin' | 'Tokyo' | 'LosAngeles'
timer_expression=
'every' INT ['mins'|'hours']
|
['every' | ordinal] days 'of' months datetime
conf = item{1,32}
item=
'-'
(description: string)?
url: url
schedule: timer_expression
(timezone: timezone_expression)?
(login: username@password)?
(times: INT)?
说明: 1,url 是cron 需要执行的代码的相对路径,如myapp/code/test.php,url 则写为test.php 2,login 表示安全选项,如果用户需要对此url 进行权限控制(如不希望web 用户通过http访问到该文件),则按格式填写username 和password 3,times 表示执行的次数,默认是循环执行,如果该值大于零,则每执行一次减一,直到等于零 4,$符号表示第几,$2 表示第二,$13 表示第十三 5,每项符合yaml语法 6,最低时间间隔为1 分钟 7,description 不是必填,默认为空;timezone 不是必填,默认为北京时间;login 不是必填,默认为无特殊权限 8,目前时区支持:北京时间、纽约时间、伦敦时间、悉尼时间、莫斯科时间、柏林时间、东京时间和洛杉矶时间 8,目前每个项目支持最多32 个item