41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Jobs\FetchAndUpsertArcadiaEmployees;
|
|
use App\Services\FlashMessageService;
|
|
use Illuminate\Bus\Dispatcher;
|
|
use Illuminate\Bus\UniqueLock;
|
|
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class EmployeesController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly FlashMessageService $flashMessageService,
|
|
private readonly Dispatcher $dispatcher,
|
|
private readonly CacheRepository $cacheRepository,
|
|
) {
|
|
}
|
|
|
|
public function launchSyncJob(FetchAndUpsertArcadiaEmployees $syncJob): RedirectResponse
|
|
{
|
|
$this->authorize('dispatchArcadiaRefreshJob', FetchAndUpsertArcadiaEmployees::class);
|
|
|
|
$uniqueLock = new UniqueLock($this->cacheRepository);
|
|
|
|
if (! $uniqueLock->acquire($syncJob)) {
|
|
$this->flashMessageService->warning(__('An employee sync is already in progress.'));
|
|
|
|
return to_route('bo.dashboard');
|
|
}
|
|
|
|
$this->dispatcher->dispatchAfterResponse($syncJob);
|
|
$this->flashMessageService->success(__('The employee sync job has been dispatched'));
|
|
|
|
return to_route('bo.dashboard');
|
|
}
|
|
}
|