mysql - Scheduled task doesn't run -
create event `set_trips_finished` on schedule every 1 day starts '2015-08-25 01:50:00' on completion preserve begin update trips set status = 0 date(created_at) < curdate(); end;
is scheduled task. fields don't updated. when run query - fields updated fine.
i have scheduled task, same syntax, scheduled run 5 minutes later, , runs fine.
i don't understand why wouldn't task run, or whether query not update table... suggestions?
update
i deleted other scheduled task (the 1 working), , set them both again, , neither fires...
see if event scheduler running:
show variables variable_name='event_scheduler'; +-----------------+-------+ | variable_name | value | +-----------------+-------+ | event_scheduler | off | +-----------------+-------+
nope
create test table:
create table trips ( id int auto_increment primary key, status int not null, created_at date not null ); insert trips(status,created_at) values (0,'2014-09-09');
create event:
delimiter $$ create event `set_trips_finished` on schedule every 1 minute starts '2015-08-23 00:00:00' on completion preserve begin update trips set status = status+1 date(created_at) < curdate(); end;$$ delimiter ;
list events schema name:
show events so_gibberish; or show events\g; -- <--------- 1 mysql> prompt show events; -- <--------- workbench / sqlyog *************************** 1. row *************************** db: so_gibberish name: set_trips_finished definer: guysmiley@localhost time zone: system type: recurring execute at: null interval value: 1 interval field: minute starts: 2015-08-23 00:00:00 ends: null status: enabled originator: 1 character_set_client: utf8 collation_connection: utf8_general_ci database collation: utf8_general_ci
look @ data might status updated:
select * trips; +----+--------+------------+ | id | status | created_at | +----+--------+------------+ | 1 | 0 | 2014-09-09 | +----+--------+------------+
well can wait day long, events aren't turned on
set global event_scheduler = on; -- turn on show variables variable_name='event_scheduler'; +-----------------+-------+ | variable_name | value | +-----------------+-------+ | event_scheduler | on | +-----------------+-------+
wait few minutes (note event runs every minute)
select * trips; +----+--------+------------+ | id | status | created_at | +----+--------+------------+ | 1 | 3 | 2014-09-09 | +----+--------+------------+
event has run 3 times. ok, looks good.
set global event_scheduler = off; -- turn off if desired
Comments
Post a Comment