最近做项目的时候设计每天定点执行的脚本,所以在这 马克一下,方便查找
set time_zone = ‘+8:00‘;
set GLOBAL event_scheduler = 1;
-- 设置该事件使用或所属的数据库base数据库
use nitrogenates;
# 如果原来存在该名字的任务计划则先删除
drop event if exists upload_to_sdmp;
# 设置分隔符为 ‘$$‘ ,mysql默认的语句分隔符为 ‘;‘ ,这样在后续的 create 到 end 这段代码都会看成是一条语句来执行
DELIMITER $$
# 创建计划任务,设置第一次执行时间为‘2014-07-30 10:00:00‘,并且每天执行一次
create event upload_to_sdmp
on schedule every 1 day starts timestamp ‘2017-01-17 07:16:00‘
#on schedule every 1 SECOND
do
# 开始该计划任务要做的事
begin
-- do something 编写你的计划任务要做的事
# INSERT test_group(name,project_id) VALUES ("haha",1);
# 获取最后一次执行的 Case_ALL,并复制到新ID中
#更改时间为当前时间
#将最后一次执行的 Case对应的 ID 变成新ID。
Insert into execution(name,project_id,test_suite_id) select name,project_id,test_suite_id from execution WHERE test_suite_id=3 ORDER BY created_time DESC LIMIT 1;
UPDATE execution SET created_time=(select CURRENT_TIMESTAMP) WHERE created_time="0000-00-00 00:00:00";
#UPDATE queue_entry SET execution_id=(SELECT id FROM execution ORDER BY id DESC LIMIT 1) WHERE execution_id=(select id from execution WHERE test_suite_id=3 ORDER BY created_time DESC LIMIT 1,1);
Insert into queue_entry(test_case_id,project_id) select test_case_id,project_id from queue_entry WHERE execution_id=(select id from execution WHERE test_suite_id=3 ORDER BY created_time DESC LIMIT 1,1);
UPDATE queue_entry SET execution_id=(SELECT id FROM execution ORDER BY id DESC LIMIT 1) WHERE execution_id=0;
#获取倒数第二条
#select id from execution WHERE test_suite_id=3 ORDER BY created_time DESC LIMIT 1,1;
#最新的 ID
#SELECT id FROM execution ORDER BY id DESC LIMIT 1;
-- 结束计划任务
end $$
# 将语句分割符设置回 ‘;‘
DELIMITER ;