* 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. */
| 1655 | * it reads until the end of the queue. |
| 1656 | */ |
| 1657 | static void |
| 1658 | ProcessBgwTaskFeedback(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 |
no test coverage detected