* DropTask * Drop an existing cron task. */
| 294 | * Drop an existing cron task. |
| 295 | */ |
| 296 | ObjectAddress |
| 297 | DropTask(ParseState *pstate, DropTaskStmt * stmt) |
| 298 | { |
| 299 | ObjectAddress address = InvalidObjectAddress; |
| 300 | char *username; |
| 301 | Oid jobid = InvalidOid; |
| 302 | |
| 303 | /* current username */ |
| 304 | username = GetUserNameFromId(GetUserId(), false); |
| 305 | |
| 306 | /* delete from pg_task */ |
| 307 | jobid = UnscheduleCronJob(stmt->taskname, username, InvalidOid, stmt->missing_ok); |
| 308 | |
| 309 | /* delete from pg_task_run_history according to the jobid */ |
| 310 | if (OidIsValid(jobid)) |
| 311 | { |
| 312 | if (!allowSystemTableMods && strncmp(stmt->taskname, DYNAMIC_TASK_PREFIX, 25) == 0) |
| 313 | { |
| 314 | ereport(ERROR, |
| 315 | (errcode(ERRCODE_RESERVED_NAME), |
| 316 | errmsg("can not drop a internal task \"%s\" paried with dynamic table", stmt->taskname), |
| 317 | errdetail("please drop the dynamic table instead"))); |
| 318 | } |
| 319 | RemoveTaskRunHistoryByJobId(jobid); |
| 320 | ObjectAddressSet(address, TaskRelationId, jobid); |
| 321 | /* Clean up dependencies */ |
| 322 | deleteSharedDependencyRecordsFor(TaskRelationId, jobid, 0); |
| 323 | } |
| 324 | |
| 325 | return address; |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * RemoveTaskById |
no test coverage detected