Problem/Motivation
In /admin/structure/salesforce/mappings/manage/{mapping}
each Mapping has it's own Push Retries limit.
This setting is then used in Drupal\salesforce_push\PushQueue::processQueue()
to limit the items retrieved from the salesforce_push_queue table.
// Claim as many items as we can from this queue and advance our counter.
// If this queue is empty, move to the next mapping.
$items = $this->claimItems($mapping->push_limit, $mapping->push_retries);
So any queue items that have more than or equal that many failures will be ignored.
However, in Drupal\salesforce_push\PushQueue::failItem()
to determine whether the item has reached the limit of retries it uses the property Drupal\salesforce_push\PushQueue::maxFails
to determine if the limit has been reached.
As far as I can tell the maxFails property shouldn't be used if number of retries is configurable for each mapping?
Steps to reproduce
Configure a mapping that will fail to be pushed (missing required data for example) and set the number of Push Retries to 2.
Process the push queue twice. On the second run (if the expire has passed) the queue item will fail again. However, the maxFails will equal the default 10 and during failItem() it will treat it as a temporary failure that should be retried when dispatching the SalesforceErrorEvent. On subsequent push queue runs the item will be skipped as it will have to many failures according to the Mapping Push Retries setting.
Proposed resolution
Use Mapping Push Retries instead of maxFails. I think that maxFails is then unused?
if ($item->failures >= $mapping->push_retries) {
$message = 'Permanently failed queue item %item failed %fail times. Exception while pushing entity %type %id for salesforce mapping %mapping. ' . $message;
}
else {
$message = 'Queue item %item failed %fail times. Exception while pushing entity %type %id for salesforce mapping %mapping. ' . $message;
}
TBH - I would think that it should also dispatch a new SalesforceEvents::PUSH_QUEUE_FAIL_PERMANENT
event so that code can catch and handle failed queue items? Currently, we have to catch all the SalesforceEvents::ERROR
and inspect the SalesforceExceptionEvent::context
to determine if a Push Queue item has reached the limit of retries.