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

Function ProcessBgwTaskFeedback

src/backend/task/pg_cron.c:1657–1757  ·  view source on GitHub ↗

* ProcessBgwTaskFeedback reads messages from a shared memory queue associated * with the background worker that is executing a given task. If the task is * still running, the function does not block if the queue is empty. Otherwise, * it reads until the end of the queue. */

Source from the content-addressed store, hash-verified

1655 * it reads until the end of the queue.
1656 */
1657static void
1658ProcessBgwTaskFeedback(CronTask *task, bool running)
1659{
1660 shm_mq_handle *responseq = task->sharedMemoryQueue;
1661 TimestampTz end_time;
1662
1663 Size nbytes;
1664 void *data;
1665 char msgtype;
1666 StringInfoData msg;
1667 shm_mq_result res;
1668
1669 end_time = GetCurrentTimestamp();
1670 /*
1671 * Message-parsing routines operate on a null-terminated StringInfo,
1672 * so we must construct one.
1673 */
1674 for (;;)
1675 {
1676 /* do not wait if the task is running */
1677 bool nowait = running;
1678
1679 /* Get next message. */
1680 res = shm_mq_receive(responseq, &nbytes, &data, nowait);
1681
1682 if (res != SHM_MQ_SUCCESS)
1683 break;
1684
1685 initStringInfo(&msg);
1686 resetStringInfo(&msg);
1687 enlargeStringInfo(&msg, nbytes);
1688 msg.len = nbytes;
1689 memcpy(msg.data, data, nbytes);
1690 msg.data[nbytes] = '\0';
1691 msgtype = pq_getmsgbyte(&msg);
1692 switch (msgtype)
1693 {
1694 case 'N':
1695 case 'E':
1696 {
1697 ErrorData edata;
1698 StringInfoData display_msg;
1699
1700 pq_parse_errornotice(&msg, &edata);
1701 initStringInfo(&display_msg);
1702 bgw_generate_returned_message(&display_msg, edata);
1703
1704 if (task_log_run)
1705 {
1706
1707 if (edata.elevel >= ERROR)
1708 UpdateJobRunDetail(task->runId, NULL, GetCronStatus(CRON_STATUS_FAILED), display_msg.data, NULL, &end_time);
1709 else if (running)
1710 UpdateJobRunDetail(task->runId, NULL, NULL, display_msg.data, NULL, NULL);
1711 else
1712 UpdateJobRunDetail(task->runId, NULL, GetCronStatus(CRON_STATUS_SUCCEEDED), display_msg.data, NULL, &end_time);
1713 }
1714

Callers 1

ManageCronTaskFunction · 0.85

Calls 14

GetCurrentTimestampFunction · 0.85
shm_mq_receiveFunction · 0.85
initStringInfoFunction · 0.85
resetStringInfoFunction · 0.85
enlargeStringInfoFunction · 0.85
pq_getmsgbyteFunction · 0.85
pq_parse_errornoticeFunction · 0.85
UpdateJobRunDetailFunction · 0.85
GetCronStatusFunction · 0.85
pq_getmsgstringFunction · 0.85
pg_cron_cmdTuplesFunction · 0.85

Tested by

no test coverage detected