23-01-2026

This commit is contained in:
Kevin Adametz 2026-01-23 17:35:23 +01:00
parent a939cd51ef
commit a8b395e20d
248 changed files with 29342 additions and 4805 deletions

View file

@ -2,8 +2,9 @@
namespace App\Jobs;
use App\Models\DhlShipment;
use App\Services\DhlApiService;
use Acme\Dhl\Models\DhlShipment;
use Acme\Dhl\Services\ShippingService;
use Acme\Dhl\Support\DhlClient;
use Exception;
use Illuminate\Bus\Queueable as BusQueueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -56,7 +57,7 @@ class CancelShipmentJob implements ShouldQueue
{
$this->dhlShipment = $dhlShipment;
$this->options = $options;
// Set queue name based on priority
if (isset($options['priority']) && $options['priority'] === 'high') {
$this->onQueue('high-priority');
@ -73,28 +74,40 @@ class CancelShipmentJob implements ShouldQueue
try {
Log::info('[DHL Queue] Starting shipment cancellation job', [
'shipment_id' => $this->dhlShipment->id,
'shipment_number' => $this->dhlShipment->shipment_number,
'dhl_shipment_no' => $this->dhlShipment->dhl_shipment_no,
'attempt' => $this->attempts(),
]);
$dhlService = new DhlApiService();
// Get DHL configuration
$settingController = new \App\Http\Controllers\SettingController;
$dhlConfig = $settingController->getDhlConfig();
// Create DHL client
$dhlClient = new DhlClient(
$dhlConfig['base_url'],
$dhlConfig['api_key'],
$dhlConfig['username'],
$dhlConfig['password']
);
// Create shipping service
$shippingService = new ShippingService($dhlClient);
// Cancel the shipment
$success = $dhlService->cancelShipment($this->dhlShipment);
$success = $shippingService->cancelLabel($this->dhlShipment->dhl_shipment_no);
if ($success) {
Log::info('[DHL Queue] Shipment cancelled successfully', [
'shipment_id' => $this->dhlShipment->id,
'shipment_number' => $this->dhlShipment->shipment_number,
'dhl_shipment_no' => $this->dhlShipment->dhl_shipment_no,
]);
} else {
throw new Exception('Cancellation returned false');
}
} catch (Exception $e) {
Log::error('[DHL Queue] Shipment cancellation failed', [
'shipment_id' => $this->dhlShipment->id,
'shipment_number' => $this->dhlShipment->shipment_number,
'dhl_shipment_no' => $this->dhlShipment->dhl_shipment_no,
'error' => $e->getMessage(),
'attempt' => $this->attempts(),
'max_tries' => $this->tries,
@ -106,6 +119,11 @@ class CancelShipmentJob implements ShouldQueue
'shipment_id' => $this->dhlShipment->id,
'error' => $e->getMessage(),
]);
// Update shipment status to indicate cancellation failed
$this->dhlShipment->update([
'status' => 'failed',
]);
}
throw $e; // Re-throw to trigger retry mechanism
@ -121,15 +139,22 @@ class CancelShipmentJob implements ShouldQueue
{
Log::error('[DHL Queue] CancelShipmentJob permanently failed', [
'shipment_id' => $this->dhlShipment->id,
'shipment_number' => $this->dhlShipment->shipment_number,
'dhl_shipment_no' => $this->dhlShipment->dhl_shipment_no,
'error' => $exception->getMessage(),
'trace' => $exception->getTraceAsString(),
]);
// You could implement additional failure handling here:
// - Send notification to admin
// - Create manual task for staff to handle cancellation
// - Update shipment status to indicate cancellation failed
// Update shipment status to indicate cancellation failed
try {
$this->dhlShipment->update([
'status' => 'failed',
]);
} catch (Exception $e) {
Log::error('[DHL Queue] Could not update shipment status after failure', [
'shipment_id' => $this->dhlShipment->id,
'error' => $e->getMessage(),
]);
}
}
/**