当前位置:网站首页>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 .
边栏推荐
- High performance erasure code coding
- Find the common ancestor of any two numbers in a binary tree
- Day12 control flow if switch while do While guessing numbers game
- WSL 2 will not be installed yet? It's enough to read this article
- 计算二叉树的最大路径和
- drools决策表的简单使用
- 堆 AcWing 838. 堆排序
- Go learning notes - go based interprocess communication
- Sweetheart leader: Wang Xinling
- BOM DOM
猜你喜欢

ThreadLocal的简单理解

浏览器存储方案

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning

BOM DOM

Redis bloom filter

Simple use of drools decision table

Openssh remote enumeration username vulnerability (cve-2018-15473)

arcgis js 4. Add pictures to x map

堆(優先級隊列)

AI mid stage technology research
随机推荐
Fluent fluent library encapsulation
FBX import under ue4/ue5 runtime
线性DP AcWing 896. 最长上升子序列 II
Writing method of then part in drools
JSON序列化 与 解析
drools决策表的简单使用
Docker compose configuration mysql, redis, mongodb
JDBC 预防sql注入问题与解决方法[PreparedStatement]
模块化 CommonJS ES Module
Simple use of drools decision table
China traffic sign detection data set
LeetCode—剑指 Offer 51. 数组中的逆序对
哈希表 AcWing 840. 模拟散列表
Deep understanding of P-R curve, ROC and AUC
Redis introduction, scenario and data type
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
Redis avalanche, penetration, breakdown
Performance tuning project case
What data types does redis have and their application scenarios
spfa AcWing 852. spfa判断负环