* ManageCronTask implements the cron task state machine. */
| 1006 | * ManageCronTask implements the cron task state machine. |
| 1007 | */ |
| 1008 | static void |
| 1009 | ManageCronTask(CronTask *task, TimestampTz currentTime) |
| 1010 | { |
| 1011 | CronTaskState checkState = task->state; |
| 1012 | int64 jobId = task->jobId; |
| 1013 | CronJob *cronJob = GetCronJob(jobId); |
| 1014 | PGconn *connection = task->connection; |
| 1015 | ConnStatusType connectionStatus = CONNECTION_BAD; |
| 1016 | TimestampTz start_time; |
| 1017 | |
| 1018 | switch (checkState) |
| 1019 | { |
| 1020 | case CRON_TASK_WAITING: |
| 1021 | { |
| 1022 | /* check if job has been removed */ |
| 1023 | if (!task->isActive) |
| 1024 | { |
| 1025 | /* remove task as well */ |
| 1026 | RemoveTask(jobId); |
| 1027 | break; |
| 1028 | } |
| 1029 | |
| 1030 | if (!CanStartTask(task)) |
| 1031 | { |
| 1032 | break; |
| 1033 | } |
| 1034 | |
| 1035 | task->pendingRunCount -= 1; |
| 1036 | if (task_use_background_worker) |
| 1037 | task->state = CRON_TASK_BGW_START; |
| 1038 | else |
| 1039 | task->state = CRON_TASK_START; |
| 1040 | |
| 1041 | task->lastStartTime = currentTime; |
| 1042 | |
| 1043 | RunningTaskCount++; |
| 1044 | |
| 1045 | /* Add new entry to audit table. */ |
| 1046 | task->runId = NextRunId(); |
| 1047 | if (task_log_run) |
| 1048 | InsertJobRunDetail(task->runId, &cronJob->jobId, |
| 1049 | cronJob->database, cronJob->userName, |
| 1050 | cronJob->command, GetCronStatus(CRON_STATUS_STARTING)); |
| 1051 | } |
| 1052 | |
| 1053 | case CRON_TASK_START: |
| 1054 | { |
| 1055 | /* |
| 1056 | * as there is no break at the end of the previous case |
| 1057 | * to not add an extra second, then do another check here |
| 1058 | */ |
| 1059 | if (!task_use_background_worker) |
| 1060 | { |
| 1061 | const char *clientEncoding = GetDatabaseEncodingName(); |
| 1062 | char nodePortString[12]; |
| 1063 | TimestampTz startDeadline = 0; |
| 1064 | |
| 1065 | const char *keywordArray[] = { |
no test coverage detected