ref
This commit is contained in:
@@ -33,12 +33,10 @@ use Espo\Entities\User;
|
||||
use Espo\Entities\Webhook;
|
||||
use Espo\Entities\WebhookEventQueueItem;
|
||||
use Espo\Entities\WebhookQueueItem;
|
||||
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\DateTime as DateTimeUtil;
|
||||
use Espo\Core\Utils\Log;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Query\Part\Condition as Cond;
|
||||
|
||||
@@ -135,7 +133,7 @@ class Queue
|
||||
->select('MIN:(number)')
|
||||
->from(WebhookQueueItem::ENTITY_TYPE)
|
||||
->where([
|
||||
'status' => 'Pending',
|
||||
'status' => WebhookQueueItem::STATUS_PENDING,
|
||||
'OR' => [
|
||||
['processAt' => null],
|
||||
['processAt<=' => DateTimeUtil::getSystemNowString()],
|
||||
@@ -162,7 +160,7 @@ class Queue
|
||||
->getRDBRepository(WebhookQueueItem::ENTITY_TYPE)
|
||||
->where([
|
||||
'webhookId' => $webhookId,
|
||||
'status' => 'Pending',
|
||||
'status' => WebhookQueueItem::STATUS_PENDING,
|
||||
'OR' => [
|
||||
['processAt' => null],
|
||||
['processAt<=' => DateTimeUtil::getSystemNowString()],
|
||||
@@ -175,7 +173,7 @@ class Queue
|
||||
/** @var ?Webhook $webhook */
|
||||
$webhook = $this->entityManager->getEntityById(Webhook::ENTITY_TYPE, $webhookId);
|
||||
|
||||
if (!$webhook || !$webhook->get('isActive')) {
|
||||
if (!$webhook || !$webhook->isActive()) {
|
||||
foreach ($itemList as $item) {
|
||||
$this->deleteQueueItem($item);
|
||||
}
|
||||
@@ -187,9 +185,9 @@ class Queue
|
||||
|
||||
$user = null;
|
||||
|
||||
if ($webhook->get('userId')) {
|
||||
if ($webhook->getUserId()) {
|
||||
/** @var ?User $user */
|
||||
$user = $this->entityManager->getEntity(User::ENTITY_TYPE, $webhook->get('userId'));
|
||||
$user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $webhook->getUserId());
|
||||
|
||||
if (!$user) {
|
||||
foreach ($itemList as $item) {
|
||||
@@ -200,7 +198,7 @@ class Queue
|
||||
}
|
||||
|
||||
$forbiddenAttributeList = $this->aclManager
|
||||
->getScopeForbiddenAttributeList($user, $webhook->get('entityType'));
|
||||
->getScopeForbiddenAttributeList($user, $webhook->getTargetEntityType());
|
||||
}
|
||||
|
||||
$actualItemList = [];
|
||||
@@ -267,7 +265,7 @@ class Queue
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $dataList
|
||||
* @param stdClass[] $dataList
|
||||
* @param WebhookQueueItem[] $itemList
|
||||
*/
|
||||
private function send(Webhook $webhook, array $dataList, array $itemList): void
|
||||
@@ -278,9 +276,7 @@ class Queue
|
||||
catch (Exception $e) {
|
||||
$this->failQueueItemList($itemList, true);
|
||||
|
||||
$this->log->error(
|
||||
"Webhook Queue: Webhook '" . $webhook->getId() . "' sending failed. Error: " . $e->getMessage()
|
||||
);
|
||||
$this->log->error("Webhook Queue: Webhook '{$webhook->getId()}' sending failed. Error: {$e->getMessage()}");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -306,7 +302,7 @@ class Queue
|
||||
|
||||
protected function logSending(Webhook $webhook, int $code): void
|
||||
{
|
||||
$this->log->debug("Webhook Queue: Webhook '" . $webhook->getId() . "' sent, response code: {$code}.");
|
||||
$this->log->debug("Webhook Queue: Webhook '{$webhook->getId()}' sent, response code: $code.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +337,7 @@ class Queue
|
||||
$itemList = $this->entityManager
|
||||
->getRDBRepository(WebhookQueueItem::ENTITY_TYPE)
|
||||
->where([
|
||||
'status' => 'Pending',
|
||||
'status' => WebhookQueueItem::STATUS_PENDING,
|
||||
'webhookId' => $webhook->getId(),
|
||||
])
|
||||
->order('number')
|
||||
@@ -357,8 +353,8 @@ class Queue
|
||||
protected function succeedQueueItem(WebhookQueueItem $item): void
|
||||
{
|
||||
$item->set([
|
||||
'attempts' => $item->get('attempts') + 1,
|
||||
'status' => 'Success',
|
||||
'attempts' => $item->getAttempts() + 1,
|
||||
'status' => WebhookQueueItem::STATUS_SUCCESS,
|
||||
'processedAt' => DateTimeUtil::getSystemNowString(),
|
||||
]);
|
||||
|
||||
@@ -367,7 +363,7 @@ class Queue
|
||||
|
||||
protected function failQueueItem(WebhookQueueItem $item, bool $force = false): void
|
||||
{
|
||||
$attempts = $item->get('attempts') + 1;
|
||||
$attempts = $item->getAttempts() + 1;
|
||||
|
||||
$maxAttemptsNumber = $this->config->get('webhookMaxAttemptNumber', self::MAX_ATTEMPT_NUMBER);
|
||||
$period = $this->config->get('webhookFailAttemptPeriod', self::FAIL_ATTEMPT_PERIOD);
|
||||
@@ -377,7 +373,6 @@ class Queue
|
||||
}
|
||||
|
||||
$dt = new DateTime();
|
||||
|
||||
$dt->modify($period);
|
||||
|
||||
$item->set([
|
||||
@@ -386,7 +381,8 @@ class Queue
|
||||
]);
|
||||
|
||||
if ($attempts >= $maxAttemptsNumber) {
|
||||
$item->set('status', 'Failed');
|
||||
$item->set('status', WebhookQueueItem::STATUS_FAILED);
|
||||
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||
$item->set('processAt', null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user