Skip to content

Commit

Permalink
Error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean committed Jun 27, 2023
1 parent 6bda8bf commit 9a7ed20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"php": "^8.1",
"justbetter/laravel-akeneo-client": "^1.1",
"justbetter/laravel-error-logger": "^2.3",
"laravel/framework": "^10.0"
"laravel/framework": "^10.0",
"spatie/laravel-activitylog": "^4.7"
},
"require-dev": {
"laravel/pint": "^1.10",
Expand Down
14 changes: 13 additions & 1 deletion src/Jobs/UpdateProductJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Queue\SerializesModels;
use JustBetter\AkeneoProducts\Contracts\UpdatesProduct;
use JustBetter\AkeneoProducts\Models\Product;
use Throwable;

class UpdateProductJob implements ShouldQueue, ShouldBeUnique
{
Expand Down Expand Up @@ -41,8 +42,19 @@ public function tags(): array
];
}

public function failed(): void
public function failed(Throwable $throwable): void
{
$this->product->failed();

activity()
->on($this->product)
->withProperties([
'message' => $throwable->getMessage(),
'code' => $throwable->getCode(),
'metadata' => [
'level' => 'error',
],
])
->log('Failed to update product in Akeneo');
}
}
3 changes: 2 additions & 1 deletion tests/Jobs/UpdateProductJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JustBetter\AkeneoProducts\Tests\Jobs;

use Exception;
use JustBetter\AkeneoProducts\Contracts\UpdatesProduct;
use JustBetter\AkeneoProducts\Jobs\UpdateProductJob;
use JustBetter\AkeneoProducts\Models\Product;
Expand Down Expand Up @@ -39,7 +40,7 @@ public function it_can_fail(): void
]);

$job = new UpdateProductJob($product);
$job->failed();
$job->failed(new Exception);

$this->assertNotNull($product->failed_at);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use JustBetter\AkeneoClient\ServiceProvider as AkeneoServiceProvider;
use JustBetter\AkeneoProducts\ServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Spatie\Activitylog\ActivitylogServiceProvider;

abstract class TestCase extends BaseTestCase
{
Expand All @@ -16,6 +17,7 @@ protected function getPackageProviders($app): array
return [
ServiceProvider::class,
AkeneoServiceProvider::class,
ActivitylogServiceProvider::class,
];
}

Expand All @@ -27,5 +29,7 @@ protected function defineEnvironment($app): void
'database' => ':memory:',
'prefix' => '',
]);

activity()->disableLogging();
}
}

0 comments on commit 9a7ed20

Please sign in to comment.