I'm working in a QA server, which turns down every day at 22:00 and turns on at 06:00 and I have an event that must execute at 06:40 but it never does, except when the server stays on.
This is the EVENT conf:
CREATE EVENT test_event
ON SCHEDULE EVERY 1 DAY
STARTS '2021-12-15 06:40:00.000'
ON COMPLETION NOT PRESERVE
ENABLE
DO CALL schema.sp()
enable the event scheduler or test if on
SET GLOBAL event_scheduler=ON;
see: https://mariadb.com/docs/reference/mdb/system-variables/event_scheduler/
it equal to MySQL
Related
I have a MySQL event and it wont go off. I have made sure that the event scheduler is on. is there something wrong with my create event code?
create event POS_Data_Import.alterSalesTransactions
on schedule
every 1 day
starts '2023-01-11 05:50:00' on completion preserve enable
do
CALL `POS_Data_Import`.`sp_Alter_CustomerExport`();
CALL `POS_Data_Import`.`sp_Alter_SalesTransactionImport`();
Use begin...end statements around the two calls like this example:
delimiter //
CREATE EVENT mydatabase.myevent
ON SCHEDULE
EVERY 1 MINUTE
starts '2023-01-12 05:50:00' on completion preserve enable
DO
BEGIN
UPDATE mydatabase.table1 SET inventory = inventory + 1;
UPDATE mydatabase.table2 SET inventory = inventory + 2;
END //
delimiter ;
After you do that, check that the event_definition has been created correctly:
select * from information_schema.events;
And that the event is enabled:
show events from mydatabase;
And that the event scheduler is running (the state should be "waiting for next activation"):
show processlist;
I have problems is: Auto-update order status if that status doesn't have any update in 30 days.
For example, the current status is " processing" and during 30days later, no more update on this. So the MySQL auto-update order status to "on Hold
I found and guest it something related to Hook, but I don't know how to implement it
depends on how you run you app. I'll suggest using e.g. some cron to get such instances and update it's status.(e.g. https://www.npmjs.com/package/node-cron)
Set it for example to run once a day, query such instances depends on build in column updatedAt. Or just to add some other column which will be updated with current date, depends what rules you want to apply
you can use cronjob.as npm says Cron is a tool that allows you to execute something on a schedule.
for install cron - 'npm i cron'
the (*) shows in order given details.
Seconds: 0-59 Minutes: 0-59 Hours: 0-23 Day of Month: 1-31 Months:
0-11 (Jan-Dec) Day of Week: 0-6 (Sun-Sat)
how to initialize cronjob:
var CronJob = require('cron').CronJob;
var job = new CronJob(
'* * * */30 * *',
function() {
console.log('every 30 days it is auto updated!');
},
null,
true,
'America/Los_Angeles'
);
make sure other parameters pass according to your application
and also cron use different port then your application.
As suggested by Damian you need to use a kind of CRON job which runs everyday to check for expired orders(created more than 30 days ago without any update).
You can use Bull with PM2
Create a processor in Bull and a queue and use the CRON functionality of Bull to set this job to run everyday usually at 12:05 AM or any time you see suitable.
The job would fetch all orders which have status "processing" and were created more than 30 days ago and update them.
Use PM2 to run Bull
I apologize if this question seems mundane, but I couldn't find a suitable answer on the web. It's my first time working with event scheduler in phpmyadmin and I think I've got the syntax down:
CREATE EVENT `zero_my_column`
ON SCHEDULE EVERY
1 MINUTE STARTS '2017-07-21 19:02:00'
DO BEGIN
UPDATE
`runners`.`run`
SET
`weekly_total` = 0
WHERE
`weekly_total` <> 0
END;
However, when I run this query in my localhost/phpmyadmin page I get the following error: #1046 - No database selected. runners is my database and run is my table. I am trying to reset the weekly_total column to zero. I'm wondering if the error arises because I need to enter validation to access the database, but I'm unsure. Any tips/hints are much appreciated.
I finally figured it out:
To create an event
Go into phpmyadmin
go to the database you will schedule the event for
click on Events tab
Then enter the script to schedule the event
I currently have a mysql database where I keep data about rented books. When somebody rents a book, I save on the database an expiration date.
So, I want to create an mysql event to update the book status when it is not returned in time. How can I create this event?
Here's what I'm trying:
CREATE EVENT `EXPIRAR` ON SCHEDULE EVERY 1
HOUR STARTS '2016-07-16 00:00:00.000000' ENDS '2018-07-29
00:00:00.000000' ON COMPLETION NOT PRESERVE ENABLE DO DO IF
mtl_aluguel.dataLimite=CURRENT_DATE THEN
UPDATE mtl_aluguel SET mtl_aluguel.estado='Expirou'
END IF
But I'm getting Syntax errors on the IF.
mtl_aluguel is the name of my table.
Like #Drew said, my event doesnt make any sense. So I updated it:
CREATE EVENT `EXPIRAR` ON SCHEDULE EVERY 1
HOUR STARTS '2016-07-16 00:00:00.000000' ENDS '2018-07-29
00:00:00.000000' ON COMPLETION NOT PRESERVE ENABLE DO UPDATE mtl_aluguel SET mtl_aluguel.estado='Expirou' WHERE mtl_aluguel.dataLimite = CURDATE() AND mtl_aluguel.estado!= 'Expirou'
I have this code
CREATE EVENT daily_production
ON SCHEDULE EVERY 1 DAY STARTS '2015-11-08 23:45:00'
DO CALL sp_produccionDiaria();
Please help me, I want to run this code every day from monday to friday, thanks.
Have you tried from event tutorial, Use delimiters, also ON COMPLETION PRESERVE
delimiter |
CREATE EVENT daily_production
ON SCHEDULE EVERY 1 DAY
STARTS '2015-11-08 23:45:00'
ON COMPLETION PRESERVE
DO
BEGIN
CALL sp_produccionDiaria();
END |
delimiter ;
Or else, Write shell script on that MySQL event and then create a cron job
00 23 * * Mon,Tue,Wed,Thu,Fri /path/mysql_event.sh