Refactor job cancellation logic in background job processing for improved clarity and maintainability

m3hm3t/issue_7896
Mehmet Yilmaz 2025-04-04 11:02:32 +00:00
parent 3c23f897e4
commit 85a1c730ce
1 changed files with 101 additions and 98 deletions

View File

@ -295,16 +295,20 @@ citus_job_wait_internal(int64 jobid, BackgroundJobStatus *desiredStatus)
if (desiredStatus) if (desiredStatus)
{ {
Oid reachedStatusOid = BackgroundJobStatusOid(job->state); Oid reachedStatusOid = BackgroundJobStatusOid(job->state);
Datum reachedStatusNameDatum = DirectFunctionCall1(enum_out, reachedStatusOid); Datum reachedStatusNameDatum = DirectFunctionCall1(enum_out,
reachedStatusOid);
char *reachedStatusName = DatumGetCString(reachedStatusNameDatum); char *reachedStatusName = DatumGetCString(reachedStatusNameDatum);
Oid desiredStatusOid = BackgroundJobStatusOid(*desiredStatus); Oid desiredStatusOid = BackgroundJobStatusOid(*desiredStatus);
Datum desiredStatusNameDatum = DirectFunctionCall1(enum_out, desiredStatusOid); Datum desiredStatusNameDatum = DirectFunctionCall1(enum_out,
desiredStatusOid);
char *desiredStatusName = DatumGetCString(desiredStatusNameDatum); char *desiredStatusName = DatumGetCString(desiredStatusNameDatum);
ereport(ERROR, ereport(ERROR,
(errmsg("Job reached terminal state \"%s\" instead of desired " (errmsg(
"state \"%s\"", reachedStatusName, desiredStatusName))); "Job reached terminal state \"%s\" instead of desired "
"state \"%s\"", reachedStatusName,
desiredStatusName)));
} }
/* Otherwise, if no desiredStatus was given, we accept this terminal state. */ /* Otherwise, if no desiredStatus was given, we accept this terminal state. */
@ -385,7 +389,6 @@ citus_cancel_job(int64 jobId)
} }
/* /*
* citus_task_wait_internal implements the waiting on a task for reuse in other areas where * citus_task_wait_internal implements the waiting on a task for reuse in other areas where
* we want to wait on tasks. * we want to wait on tasks.