0

This schedular i made doesn't work how i would like it to work.

The idea is that it will run every day in a time periode from 06:15:00 till 23:59:59 and in that only periode run every hour

That means it will run on 06:15 - 07:15 - 08:15 etc.. till 23:15 and start over again the next day

Server version: innodb_version:5.7.25

DELIMITER |

/*  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  */ 
ALTER 
    EVENT `Database`.`Import_data01_view` 
    ON SCHEDULE 
        EVERY 1 HOUR 
        STARTS '2019-04-15 06:15:00'  ON COMPLETION PRESERVE ENABLE
    DO BEGIN

/* do things */


END |


DELIMITER ;

With the info i found my own solution for it:

DELIMITER |

/*  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  */ 
ALTER 
    EVENT `Database`.`Import_data01_view` 
    ON SCHEDULE 
        EVERY 1 HOUR
        STARTS str_to_date( date_format(now(), '%Y%m%d 0615'), '%Y%m%d %H%i' )
        ON COMPLETION PRESERVE ENABLE
    DO BEGIN


 IF time(CURRENT_TIMESTAMP) between time('06:14:59') and time('23:59:59')
      THEN

/* doe something */



end if;







END |


DELIMITER ;
  • have you tried without the starts clause? (i'm asking because to me here is still around 12am) – Jorge Campos Apr 15 at 7:14
  • Also, the documentation specify starts and ends clause. dev.mysql.com/doc/refman/5.7/en/create-event.html since you want it to run just for that day you should have the ends clause – Jorge Campos Apr 15 at 7:18
  • Then i get a error : Errocode: 1525 Incorrect STARTS value: '06:15:00' – F T Apr 15 at 7:18
  • I don't want it run only for that day.. it need to run it everyday – F T Apr 15 at 7:26
  • Specify MySQL version. Simplify your event till simple stored procedure call. it will run every day in a time periode from 06:15:00 till 23:59:59 No, it will run 24 times per day (at each XX:15:00) except first day. – Akina Apr 15 at 7:59
0
-- main action to perform at 6:15 - 7:15 - ... 23:15
CREATE PROCEDURE main_action()
BEGIN
    -- ...
END;

-- event procedure
CREATE PROCEDURE evt_action()
BEGIN
IF HOUR(CURRENT_TIMESTAMP) > 5 THEN 
    CALL main_action();
END IF;
END;

-- event
CREATE EVENT evt_name
ON SCHEDULE EVERY 1 HOUR STARTS '2019-04-15 06:15:00'
DO CALL evt_action();

-- start scheduler
SET GLOBAL event_scheduler = ON;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.