当前位置:网站首页>Use MySQL events to regularly perform post seven world line tasks
Use MySQL events to regularly perform post seven world line tasks
2022-07-02 12:39:00 【Time chaser】
Recently I did a recruitment project , There is a need for regular offline in the project . Before doing it, I've been thinking about using window service , Still use scheduling , In the end, I chose to use mysql Timing events , Because it's so simple and convenient .
Ideas : First create a stored procedure , Update the corresponding position status through cursor traversal , Let's create a scheduled event after , Don't talk too much nonsense, just go to the code
First create a stored procedure :
CREATE DEFINER = CURRENT_USER PROCEDURE `TimedDownLine`()
BEGIN
-- Declare variables ( For inserting data )
DECLARE PostID INT;# Position ID
DECLARE DifferDay INT;# return int
DECLARE done INT DEFAULT 0;# The basis for judging whether there is information 0 Indicates that there is data
DECLARE Integral_cursor cursor for SELECT id,TIMESTAMPDIFF(DAY, ReleaseEnd, now()) AS intervalday FROM postrelease WHERE PostType=1;# Query all online position information (1 Indicates online position ,2 Indicates the offline position )
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;# No data is returned and the status is changed to 1
-- Open cursor
OPEN Integral_cursor;
# Start the cycle
WHILE done=0 DO
#REPEAT
# Cursor assignment ( The cursor will only execute downward )
FETCH Integral_cursor INTO PostID,DifferDay;
IF(done=0&&DifferDay>7)
THEN UPDATE postrelease SET PostType=2 where ID=PostID;
end IF;
# The loop ends
#UNTIL done=1 END REPEAT;
END WHILE;
SET done=1;# Change state , Indicates the end of the cycle
-- Close cursor
ENDCreate database events :
# Check whether the database event is enabled
SHOW VARIABLES LIKE 'event_scheduler'
show variables like '%event%';
# Set the current event on
SET GLOBAL event_scheduler = 1;
# View scheduled tasks
select * from mysql.event;
SELECT * FROM information_schema.events;
# It starts every morning
select DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 13 HOUR)
# Turn off scheduled tasks
DROP event temp_event;
# It starts every morning ( Create timed events )
CREATE EVENT IF NOT EXISTS TimeDownlines_event
ON SCHEDULE EVERY 1 DAY STARTS DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 0 HOUR)
ON COMPLETION PRESERVE ENABLE # Start the scheduled task on time
DO CALL TimedDownLine();In this way, it is possible to deal with some businesses rather than complex scheduled tasks , And the development is fast , Next time I have time, I will window The scheduled task of the service is written .
边栏推荐
- bellman-ford AcWing 853. 有边数限制的最短路
- China traffic sign detection data set
- 甜心教主:王心凌
- Redis sentinel mechanism and configuration
- What data types does redis have and their application scenarios
- WSL 2 will not be installed yet? It's enough to read this article
- 哈希表 AcWing 840. 模拟散列表
- Mongodb redis differences
- The blink code based on Arduino and esp8266 runs successfully (including error analysis)
- 怎样写一篇赏心悦目的英文数学论文
猜你喜欢

This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry

JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)

线性DP AcWing 897. 最长公共子序列
![1380. Lucky numbers in the matrix [two-dimensional array, matrix]](/img/8c/c050af5672268bc7e0df3250f7ff1d.jpg)
1380. Lucky numbers in the matrix [two-dimensional array, matrix]

drools中then部分的写法

Floyd AcWing 854. Floyd求最短路

Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately

浏览器node事件循环

寻找二叉树中任意两个数的公共祖先

Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
随机推荐
LeetCode—剑指 Offer 37、38
堆 AcWing 838. 堆排序
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
CDH6之Sqoop添加数据库驱动
Go learning notes - multithreading
China traffic sign detection data set
CDA data analysis -- common knowledge points induction of Excel data processing
The differences and relationships among port, targetport, nodeport and containerport in kubenetes
Sort---
BOM DOM
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
Addition, deletion, modification and query of MySQL table (Advanced)
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Performance tuning project case
单指令多数据SIMD的SSE/AVX指令集和API
深拷貝 事件總線
Drools dynamically add, modify, and delete rules
Distributed machine learning framework and high-dimensional real-time recommendation system
MySQL与PostgreSQL抓取慢sql的方法
High performance erasure code coding