# Autogedal_AwbRetry

`Autogedal_AwbRetry` adds asynchronous retry handling for AWB generation failures in Magento.

## What it does

- catches AWB generation failures from courier integrations
- automatically retries generation up to the configured attempt limit
- replays queued retries after the configured delay, so transient timeout failures can be retried 2-3 minutes later
- keeps manual retries immediate while automatic retries use the configured delay
- automatic retries are limited to transient failures such as timeout and upstream availability errors
- invoice generation is already gated by the AWB status in the existing order flow; this module does not add a separate invoice retry path
- logs every failure in a dedicated AWB error table
- stores the retry context, carrier data, AWB data, related order, timestamps, and the last error message
- prefers the live `eadesign_awb.awb_number` before falling back to the retry log or calling the courier again
- sends an email notification once per error log when the failure is first logged
- marks whether the notification email was sent
- exposes all failure records in an admin grid
- allows single-record manual retry from the grid
- allows mass manual retry from the grid
- re-queues manual retries through the Magento message queue
- processes queued retries asynchronously through a consumer
- updates the log status while queued, processing, failed, and resolved
- resolves the record when AWB generation succeeds
- logs a new failure again if the retry path fails

## Admin configuration

The module provides configuration for:

- maximum automatic retry attempts
- automatic retry delay in milliseconds
- transient failure patterns used to decide which errors are retried automatically
- email template for failure notifications
- notification recipient addresses

## Admin UI

The AWB error grid shows:

- ID
- created date
- last retry date
- resolved date
- AWB ID
- order increment ID
- carrier
- attempt count
- status
- email sent flag
- last error message
- row actions

## Queue topic

- `autogedal.awb_retry.process`

## Notes

- Later successful courier calls from cron or admin also resolve the existing log for the same AWB ID and carrier, recording the returned AWB number. Error messages, attempt counts and email history remain available.
- Already resolved logs are skipped by queued retry jobs.
- Magento's default cron group runs `autogedal_awb_retry_reconcile` every five minutes, reconciling up to 100 stale logs per run using the same active saved-AWB checks as the manual command. Individual write failures are logged and retried on a later run. This also repairs historical entries automatically, without courier calls or notifications.
- To reconcile older stale logs using active, saved AWB rows, preview with `bin/magento autogedal:awb-retry:reconcile`, then save with `bin/magento autogedal:awb-retry:reconcile --apply`. This does not call couriers, change orders, send SMS or send email. Reconciled timestamps record the reconciliation time, since the original generation time is unavailable.

- Date values are stored in UTC and displayed in Magento local time in the admin grid.
- Manual retries are queued, not executed inline.
- The default retry delay is 180000 ms, which matches a 3 minute interval.
- Automatic retries are requeued until the configured max attempts is reached.
- The retry processor prefers the current AWB number from `eadesign_awb`, then the cached retry log value, before generating a new one.
