I have a stored procedure which picks (nu-processed) one row from a table and do the processing of the data and then mark that as processed. I am calling this stored procedure from MySQL Events/Job and I have selected the schedule of this as every second. Now if this stored procedure take 1 to 5 seconds to process single row based on the server load, I want to handle this execution of stored procedure to run if previous execution is completed otherwise same row will be picked for processing multiple times.
Following is the sample code which I am using right now.
DELIMITER $$
CREATE DEFINER=`root`@`localhost` EVENT `sp_process_data_row_by_row` ON SCHEDULE EVERY 1 SECOND STARTS '2022-10-10 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
DO RELEASE_LOCK('sp_process_data_row_by_row');
END;
IF GET_LOCK('sp_process_data_row_by_row', 0) THEN
BEGIN
CALL sp_process_data_row_by_row( 'migrate_data' , NULL, NULL, NULL );
END IF;
DO RELEASE_LOCK('sp_process_data_row_by_row');
END$$
DELIMITER ;
Thanks ! RJ