Created
June 13, 2020 22:51
-
-
Save joefrancia/7de6c065c22e3e8b442c46458d6c1bfc to your computer and use it in GitHub Desktop.
Avoid SQL contention in events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER // | |
CREATE EVENT testlock_event ON SCHEDULE EVERY 2 SECOND DO | |
BEGIN | |
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION | |
BEGIN | |
DO RELEASE_LOCK('testlock_event'); | |
END; | |
IF GET_LOCK('testlock_event', 0) THEN | |
-- add some business logic here, for example: | |
-- insert into test.testlock_event values(NULL, NOW()); | |
END IF; | |
DO RELEASE_LOCK('testlock_event'); | |
END; | |
// | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment