It is necessary to frequently trigger an action at a fixed time point and at intervals of time. For the convenience of use, there is a timed task, which greatly reduces the repetition of work and improves efficiency.
The content of the timed task
Based on the background of the scheduled task, the content of the scheduled task includes: creation of the scheduled task, automatic execution of the task at the time point, deletion of the task, modification of the task content (task id, closing and opening of the task, trigger time of the task, trigger time interval, task content, etc.).
timed task
Create a table
CREATE TABLE tb_test(insert_date timestamp default null,id int default null);
Display information
CREATE TABLE
create table successfully
Create a scheduled task
The timing content is: insert into the table tb_test every one minute (current system time, 1)
SELECT pkg_service.job_submit(1,'insert into tb_test values(sysdate,1);',sysdate,'''1min''::interval');
job_submit
-------------
1
(1 row)
SELECT \* FROM tb_test;
insert_date | id
2022-09-02 17:50:04 | 1
2022-09-02 17:51: 04 | 1
2022-09-02 17:52:04 | 1
(3 rows)
Timed task executed successfully
Timed task stop
SELECT pkg_service.job_finish(1,true);
job_finish
-------------
(1 row)
Scheduled task start
SELECT pkg_service.job_finish(1,false);
job_finish
-------------
(1 row)
Delete scheduled tasks
SELECT pkg_service.job_cancel(1);
job_cancel
-------------
(1 row)
Top comments (0)