DBE_TASK
API Description
Table DBE_TASK lists all APIs supported by the DBE_TASK package.
API |
Description |
---|---|
Submits a scheduled task. The job ID is automatically generated by the system. |
|
Same as DBE_TASK.SUBMIT. However, It provides syntax compatibility parameters. |
|
Submits a scheduled task. The job ID is specified by the user. |
|
Removes a scheduled task by job ID. |
|
Executes a scheduled task. |
|
Disables or enables scheduled task execution. |
|
Modifies user-definable attributes of a scheduled task, including the task content, next-execution time, and execution interval. |
|
Same as DBE_TASK.UPDATE. However, It provides syntax compatibility parameters. |
|
Modifies the content attribute of a scheduled task. |
|
Modifies the next-execution time attribute of a scheduled task. |
|
Modifies the execution interval attribute of a scheduled task. |
- DBE_TASK.SUBMIT
The stored procedure SUBMIT submits a scheduled task provided by the system.
The prototype of the DBE_TASK.SUBMIT function is as follows:
1 2 3 4 5 6
DBE_TASK.SUBMIT( what IN TEXT, next_time IN TIMESTAMP DEFAULT sysdate, interval_time IN TEXT DEFAULT 'null', id OUT INTEGER )RETURN INTEGER;
When a scheduled task is created (using DBE_TASK), the system binds the current database and the username to the task by default. The API function can be called using CALL or SELECT. If the API function is called using SELECT, you do not need to set the output parameter. If the API function is called using CALL, you need to set the output parameter. To call this function within a stored procedure, use perform. If the committed SQL statement task uses a non-public schema, specify the schema to a table schema or a function schema, or add set current_schema = xxx before the SQL statement.
Table 2 DBE_TASK.SUBMIT parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
what
Text
IN
No
SQL statement to be executed. One or multiple DDLs (excluding database-related operations), DMLs, anonymous blocks, and statements for calling stored procedures, or all four combined are supported.
next_time
Timestamp
IN
No
Specifies the next time the job will be executed. The default value is the current system time (sysdate). If the specified time has past, the job is executed at the time it is submitted.
interval_time
Text
IN
Yes
Calculates the next time to execute the job. It can be an interval expression, or sysdate followed by a numeric value, for example, sysdate+1.0/24. If this parameter is left empty or set to null, the job will be executed only once, and the job status will change to 'd' afterward.
id
Integer
OUT
No
Specifies the job ID. The value ranges from 1 to 32767. When SELECT is used for calling, this parameter cannot be added. When CALL is used for calling, this parameter must be added.
When you create a user using the what parameter, the plaintext password of the user is recorded in the log. Therefore, you are advised not to do so. Tasks created using this API may not be highly available. You are advised to use PKG_SERVICE.SUBMIT_ON_NODES to create a task and specify the CCN as the job execution node.
Example:
1 2 3 4 5 6 7 8 9 10 11 12
select DBE_TASK.SUBMIT('call pro_xxx();', to_date('20180101','yyyymmdd'),'sysdate+1'); select DBE_TASK.SUBMIT('call pro_xxx();', to_date('20180101','yyyymmdd'),'sysdate+1.0/24'); CALL DBE_TASK.SUBMIT('INSERT INTO T_JOB VALUES(1); call pro_1(); call pro_2();', add_months(to_date('201701','yyyymm'),1), 'date_trunc(''day'',SYSDATE) + 1 +(8*60+30.0)/(24*60)' ,:jobid); DECLARE jobid int; BEGIN PERFORM DBE_TASK.SUBMIT('call pro_xxx();', sysdate, 'interval ''5 minute''', jobid); END; /
- DBE_TASK.JOB_SUBMIT
The stored procedure SUBMIT submits a scheduled task provided by the system. In addition, it provides additional compatibility parameters.
The DBE_TASK.JOB_SUBMIT function prototype is as follows:1 2 3 4 5 6 7 8 9
DBE_TASK.JOB_SUBMIT( job OUT INTEGER, what IN TEXT, next_date IN TIMESTAMP DEFAULT sysdate, job_interval IN TEXT DEFAULT 'null', no_parse IN BOOLEAN DEFAULT false, instance IN INTEGER DEFAULT 0, force IN BOOLEAN DEFAULT false )RETURN INTEGER;
Table 3 DBE_TASK.JOB_SUBMIT parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
job
Integer
OUT
No
Specifies the job ID. The value ranges from 1 to 32767. When dbe.job_submit is called using SELECT, this parameter can be omitted.
what
Text
IN
No
SQL statement to be executed. One or multiple DDLs (excluding database-related operations), DMLs, anonymous blocks, and statements for calling stored procedures, or all four combined are supported.
next_date
Timestamp
IN
Yes
Specifies the next time the job will be executed. The default value is the current system time (sysdate). If the specified time has past, the job is executed at the time it is submitted.
job_interval
Text
IN
Yes
Calculates the next time to execute the job. It can be an interval expression, or sysdate followed by a numeric value, for example, sysdate+1.0/24. If this parameter is left empty or set to null, the job will be executed only once, and the job status will change to 'd' afterward.
no_parse
Boolean
IN
Yes
The default value is false, which is used only for syntax compatibility.
instance
Integer
IN
Yes
The default value is 0, which is used only for syntax compatibility.
force
Boolean
IN
Yes
The default value is false, which is used only for syntax compatibility.
Example:1 2 3 4 5 6 7 8 9
DECLARE id integer; BEGIN id = DBE_TASK.JOB_SUBMIT( what => 'insert into t1 values (1, 2)', job_interval => 'sysdate + 1' --daily ); END; /
- DBE_TASK.ID_SUBMIT
ID_SUBMIT has the same syntax function as SUBMIT, but the first parameter of ID_SUBMIT is an input parameter, that is, a specified job ID. In contrast, that last parameter of ID_SUBMIT is an output parameter, indicating the job ID automatically generated by the system.
1 2 3 4 5
DBE_TASK.ID_SUBMIT( id IN BIGINT, what IN TEXT, next_time IN TIMESTAMP DEFAULT sysdate, interval_time IN TEXT DEFAULT 'null');
Example:
1
CALL dbe_task.id_submit(101, 'insert_msg_statistic1;', sysdate, 'sysdate+3.0/24');
- DBE_TASK.CANCEL
The stored procedure CANCEL deletes a specified task.
The prototype of the DBE_TASK.CANCEL function is as follows:
1
CANCEL(id IN INTEGER);
Table 4 DBE_TASK.CANCEL parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
Integer
IN
No
Specifies the job ID.
Example:
CALL dbe_task.cancel(101);
- DBE_TASK.RUN
The stored procedure runs a scheduled task.
The prototype of the DBE_TASK.RUN function is as follows:
1 2 3
DBE_TASK.RUN( job IN BIGINT, force IN BOOLEAN DEFAULT FALSE);
Table 5 DBE_TASK.RUN parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
job
bigint
IN
No
Specifies the job ID.
force
Boolean
IN
Yes
Used only for syntax compatibility.
Example:
1 2 3 4 5
BEGIN DBE_TASK.ID_SUBMIT(12345, 'insert_msg_statistic1;', sysdate, 'sysdate+3.0/24'); DBE_TASK.RUN(12345); END; /
- DBE_TASK.FINISH
The stored procedure FINISH disables or enables a scheduled task.
The prototype of the DBE_TASK.FINISH function is as follows:
1 2 3 4
DBE_TASK.FINISH( id IN INTEGER, broken IN BOOLEAN, next_time IN TIMESTAMP DEFAULT sysdate);
Table 6 DBE_TASK.FINISH parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
Integer
IN
No
Specifies the job ID.
broken
Boolean
IN
No
Specifies the status flag, true for broken and false for not broken. The current job is updated based on the parameter value true or false. If the parameter is left empty, the job status remains unchanged.
next_time
Timestamp
IN
Yes
Specifies the next execution time. The default value is the current system time. If broken is set to true, next_time is updated to '4000-1-1'. If broken is set to false and next_time is not empty, next_time is updated for the job. If next_time is empty, it will not be updated. This parameter can be omitted, and its default value will be used in this case.
Example:
1 2
CALL dbe_task.finish(101, true); CALL dbe_task.finish(101, false, sysdate);
- DBE_TASK.UPDATE
The stored procedure UPDATE modifies user-definable attributes of a task, including the task content, next-execution time, and execution interval.
The prototype of the DBE_TASK.UPDATE function is as follows:
1 2 3 4 5
dbe_task.UPDATE( id IN INTEGER, content IN TEXT, next_time IN TIMESTAMP, interval_time IN TEXT);
Table 7 DBE_TASK.UPDATE parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
Integer
IN
No
Specifies the job ID.
content
Text
IN
Yes
Specifies the name of the stored procedure or SQL statement block that is executed. If this parameter is left empty, the system does not update the content parameter for the specified job. Otherwise, the system updates the content parameter for the specified job.
next_time
Timestamp
IN
Yes
Specifies the next execution time. If this parameter is left empty, the system does not update the next_time parameter for the specified job. Otherwise, the system updates the next_time parameter for the specified job.
interval_time
Text
IN
Yes
Specifies the time expression for calculating the next time the job will be executed. If this parameter is left empty, the interval_time parameter is not updated for the specified job. If not, whether the interval_time parameter is valid time or interval type is checked. If it is, it is updated for the specified job. If this parameter is set to null, the job will be executed only once, and the job status will change to 'd' afterward.
Example:
1 2
CALL dbe_task.update(101, 'call userproc();', sysdate, 'sysdate + 1.0/1440'); CALL dbe_task.update(101, 'insert into tbl_a values(sysdate);', sysdate, 'sysdate + 1.0/1440');
- DBE_TASK.CHANGE
The stored procedure UPDATE modifies user-definable attributes of a task, including the task content, next-execution time, and execution interval.
The prototype of the DBE_TASK.CHANGE function is as follows:
1 2 3 4 5 6 7
DBE_TASK.CHANGE( job IN INTEGER, what IN TEXT DEFAULT NULL, next_date IN TIMESTAMP DEFAULT NULL, job_interval IN TEXT DEFAULT NULL, instance IN INTEGER DEFAULT NULL, force IN BOOLEAN DEFAULT false);
Table 8 DBE_TASK.CHANGE parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
job
Integer
IN
No
Specifies the job ID.
what
Text
IN
Yes
Specifies the name of the stored procedure or SQL statement block that is executed. If this parameter is left empty, the system does not update the what parameter for the specified job. Otherwise, the system updates the what parameter for the specified job.
next_date
Timestamp
IN
Yes
Specifies the next execution time. If this parameter is left empty, the system does not update the next_time parameter for the specified job. Otherwise, the system updates the next_date parameter for the specified job.
job_interval
Text
IN
Yes
Specifies the time expression for calculating the next time the job will be executed. If this parameter is left empty, the system does not update the job_interval parameter for the specified job. Otherwise, the system updates the job_interval parameter for the specified job after necessary validity check. If this parameter is set to null, the job will be executed only once, and the job status will change to 'd' afterward.
instance
Integer
IN
Yes
Used only for syntax compatibility.
force
Boolean
IN
No
Used only for syntax compatibility.
1 2 3 4 5 6 7
BEGIN DBE_TASK.CHANGE( job => 1234, what => 'insert into t2 values (2);' ); END; /
- DBE_TASK.CONTENT
The stored procedure CONTENT modifies the procedures to be executed by a specified task.
The function prototype of DBE_TASK.CONTENT is as follows:
1 2 3
DBE_TASK.CONTENT( id IN INTEGER, content IN TEXT);
Table 9 DBE_TASK.CONTENT parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
Integer
IN
No
Specifies the job ID.
content
Text
IN
No
Specifies the name of the stored procedure or SQL statement block that is executed.
- If the value specified by the content parameter is one or multiple executable SQL statements, program blocks, or stored procedures, this procedure can be executed successfully; otherwise, it will fail to be executed.
- If the value specified by the content parameter is a simple statement such as INSERT and UPDATE, a schema name must be added in front of the table name.
Example:
1 2
CALL dbe_task.content(101, 'call userproc();'); CALL dbe_task.content(101, 'insert into tbl_a values(sysdate);');
- DBE_TASK.NEXT_TIME
The stored procedure NEXT_TIME modifies the next-execution time attribute of a task.
The prototype of the DBE_TASK.NEXT_TIME function is as follows:
1 2 3
DBE_TASK.NEXT_TIME( id IN BIGINT, next_time IN TEXT);
Table 10 DBE_TASK.NEXT_TIME parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
bigint
IN
No
Specifies the job ID.
next_time
Text
IN
No
Specifies the next execution time.
If the specified next_time value is earlier than the current date, the job is executed once immediately.
Example:
1
CALL dbe_task.next_time(101, sysdate);
- DBE_TASK.INTERVAL
The stored procedure INTERVAL modifies the execution interval attribute of a task.
The prototype of the DBE_TASK.INTERVAL function is as follows:
1 2 3
DBE_TASK.INTERVAL( id IN INTEGER, interval_time IN TEXT);
Table 11 DBE_TASK.INTERVAL parameters Parameter
Type
Input/Output Parameter
Can Be Empty
Description
id
Integer
IN
No
Specifies the job ID.
interval_time
Text
IN
Yes
Specifies the time expression for calculating the next time the job will be executed. If this parameter is left empty or set to null, the job will be executed only once, and the job status will change to 'd' afterward. interval must be a valid time or interval type.
Example:
1
CALL dbe_task.interval(101, 'sysdate + 1.0/1440');
For a job that is currently running (that is, job_status is 'r'), it is not allowed to use cancel, update, next_time, content, or interval to delete or modify job parameters.
Constraints
- After a job is created by using SUMMIT/ID_SUBMIT, the job belongs to the current coordinator (that is, the job is scheduled and executed only on the current coordinator). Other coordinators do not schedule and execute the job. If the coordinator node is faulty, the job cannot be properly executed. You are advised to use the PKG_SERVICE.SUBMIT_ON_NODES API to specify the job execution node as CCN to ensure that the job is still available when a node is faulty. Not all coordinators can query, modify, and delete tasks created on other CNs.
- You can create, update, and delete tasks only using the procedures provided by the dbe_task package. These procedures synchronize task information between different CNs and associate primary keys between pg_job and pg_job_proc. If you use DML statements to add, delete, or modify records in pg_job, task information will become inconsistent between CNs and system catalogs may fail to be associated, compromising internal task management.
- Each task created by a user is bound to a CN. If the CN fails while a task is being executed, the task status cannot be updated in real time and will stay at 'r'. The task status will be updated to 's' only after the CN recovers. When a CN fails, all tasks on this CN cannot be scheduled or executed until the CN is restored manually, or deleted and then replaced.
- For each task, the bound CN updates the real-time task information (including the task status, last execution start time, last execution end time, next execution start time, the number of execution failures [if any]) to pg_job, and synchronizes the information to other CNs, ensuring consistent task information between different CNs. In the case of faults on other CNs, task information synchronization is reattempted by the bound CN, which increases job execution time. Although task information fails to be synchronized between CNs, task information can still be properly updated in pg_job on the bound CN and the task can be executed successfully. After the faulty CN recovers, task information such as task execution time and status in its pg_job may be incorrect and will be updated only after the task is executed again on the bound CN.
- For each job, a thread is established to execute it. If multiple jobs are triggered concurrently as scheduled, the system will need some time to start the required threads, resulting in a latency of 0.1 ms in job execution.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot