How to create an "Event Scheduler" in Mysql whose range value comes from the database itself?

Asked

Viewed 111 times

0

I am using the following code to generate a Task or Event Schedule in Mysql every 10 seconds:

delimiter |
CREATE EVENT gera_financeiro_contrato
    ON SCHEDULE EVERY 10 SECOND STARTS CURRENT_TIMESTAMP ON COMPLETION PRESERVE
    COMMENT 'Gera financeiro no contrato'
    DO
    BEGIN
        insert into grupos (nome, ) values (concat('teste -', UNIX_TIMESTAMP() ) );
    END|

delimiter ; 

The above code is correct and working, but I need to let the user change the frequency of the execution of Task, for example if the task was created to run every 10 seconds ON SCHEDULE EVERY 10 SECOND, how I do for the task read a given table and get the interval value for execution?

1 answer

0


You need to do a subquery to know the new value of the range, the code would look like this:

delimiter |
CREATE EVENT gera_financeiro_contrato
    ON SCHEDULE EVERY (select valor from tabela where campo = especificacao) SECOND STARTS CURRENT_TIMESTAMP ON COMPLETION PRESERVE
    COMMENT 'Gera financeiro no contrato'
    DO
    BEGIN
        insert into grupos (nome, ) values (concat('teste -', UNIX_TIMESTAMP() ) );
    END|

delimiter ; 
  • Your reply helped me very much thanks, but I have not solved my whole problem and I only saw it after making the task work, thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.