diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 42c4749..433cb8c 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -5,8 +5,8 @@ use App\Jobs\FetchGoogleFit; use App\Repositories\StepActivityRepositoryInterface; use App\Services\GoogleApiService; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; use Inertia\Inertia; class DashboardController extends Controller @@ -30,7 +30,8 @@ public function index() public function sync() { $user = Auth::user(); - FetchGoogleFit::dispatch($user)->onQueue('stepsCount'); + FetchGoogleFit::dispatch($user); + Log::info("Running queue..."); return $this->stepActivityRepository->getInToday($user->id); } } diff --git a/app/Jobs/FetchGoogleFit.php b/app/Jobs/FetchGoogleFit.php index a1c1967..e682767 100644 --- a/app/Jobs/FetchGoogleFit.php +++ b/app/Jobs/FetchGoogleFit.php @@ -4,22 +4,14 @@ use App\Models\User; use App\Repositories\StepActivityRepositoryInterface; -use App\Repositories\TokenRepositoryInterface; use App\Services\GoogleApiService; -use Illuminate\Cache\Repository; -use Illuminate\Contracts\Queue\ShouldBeUnique; -use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Queue\Queueable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\Middleware\WithoutOverlapping; -use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; -class FetchGoogleFit implements ShouldQueue, ShouldBeUnique +class FetchGoogleFit implements ShouldQueue { use Queueable; use Dispatchable; @@ -31,27 +23,13 @@ public function __construct( ) { } - public function uniqueId(): string - { - return $this->user->id; - } - - public function uniqueVia(): Repository - { - return Cache::driver('redis'); - } - - public function middleware(): array - { - return [(new WithoutOverlapping($this->user->id))->releaseAfter(60)]; - } - public function handle(GoogleApiService $googleApiService, StepActivityRepositoryInterface $stepActivityRepository): void { - DB::transaction(function () use ($googleApiService, $stepActivityRepository) { - Log::info("Queue FetchGoogleFit: STARTING.."); - $data = $googleApiService->syncData($this->user); - $step = $stepActivityRepository->getInToday($this->user->id); + Log::info("Queue FetchGoogleFit: STARTING.."); + $data = $googleApiService->syncData($this->user); + $step = $stepActivityRepository->getInToday($this->user->id); + + DB::transaction(function () use ($stepActivityRepository, $step, $data) { if (!$step) { $stepActivityRepository->create($this->user, [ diff --git a/resources/js/Pages/Dashboard.tsx b/resources/js/Pages/Dashboard.tsx index ebe59cc..2bf3221 100644 --- a/resources/js/Pages/Dashboard.tsx +++ b/resources/js/Pages/Dashboard.tsx @@ -8,7 +8,7 @@ import { faWalking, } from "@fortawesome/free-solid-svg-icons"; import { CircularProgress, createTheme, ThemeProvider } from "@mui/material"; -import { Head, Link } from "@inertiajs/react"; +import { Head } from "@inertiajs/react"; import { useQuery } from "react-query"; import { useState } from "react";