MCPcopy Create free account
hub / github.com/apache/cloudberry / ManageCronTask

Function ManageCronTask

src/backend/task/pg_cron.c:1008–1553  ·  view source on GitHub ↗

* ManageCronTask implements the cron task state machine. */

Source from the content-addressed store, hash-verified

1006 * ManageCronTask implements the cron task state machine.
1007 */
1008static void
1009ManageCronTask(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[] = {

Callers 1

ManageCronTasksFunction · 0.85

Calls 15

GetCronJobFunction · 0.85
RemoveTaskFunction · 0.85
CanStartTaskFunction · 0.85
NextRunIdFunction · 0.85
InsertJobRunDetailFunction · 0.85
GetCronStatusFunction · 0.85
GetDatabaseEncodingNameFunction · 0.85
PQconnectStartParamsFunction · 0.85
PQsetnonblockingFunction · 0.85
PQstatusFunction · 0.85
UpdateJobRunDetailFunction · 0.85
shm_toc_estimateFunction · 0.85

Tested by

no test coverage detected