diff --git a/Dockerfile b/Dockerfile index 5a8a338..f0ae421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,12 +41,15 @@ COPY --from=node_builder /app/public/build /app/public/build RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader # Zorg voor de juiste opslagpermissies en database bestand -RUN mkdir -p /app/storage /app/bootstrap/cache /app/database \ - && touch /app/database/database.sqlite \ +RUN mkdir -p /app/storage /app/bootstrap/cache /app/database /app/storage/logs \ + && touch /app/database/database.sqlite /app/storage/logs/cron.log \ && chown -R www-data:www-data /app/storage /app/bootstrap/cache /app/database \ && chmod -R 775 /app/storage /app/bootstrap/cache /app/database +# Configureer crontab voor Laravel Scheduler (draait elke minuut php artisan schedule:run) +RUN echo "* * * * * cd /app && php artisan schedule:run >> /app/storage/logs/cron.log 2>&1" > /etc/crontabs/root + EXPOSE 80 -CMD ["sh", "-c", "php artisan storage:link && mkdir -p /app/database /app/storage/framework/cache /app/storage/framework/sessions /app/storage/framework/views /app/storage/logs && touch /app/database/database.sqlite && chmod -R 777 /app/database /app/storage && php artisan migrate --force && php artisan db:seed --force && frankenphp run --config /etc/caddy/Caddyfile"] +CMD ["sh", "-c", "php artisan storage:link && mkdir -p /app/database /app/storage/framework/cache /app/storage/framework/sessions /app/storage/framework/views /app/storage/logs && touch /app/database/database.sqlite /app/storage/logs/cron.log && chmod -R 777 /app/database /app/storage && php artisan migrate --force && php artisan db:seed --force && crond -b -l 2 && frankenphp run --config /etc/caddy/Caddyfile"] diff --git a/app/Http/Controllers/Admin/MakerWorldController.php b/app/Http/Controllers/Admin/MakerWorldController.php index a523221..b12f3bd 100644 --- a/app/Http/Controllers/Admin/MakerWorldController.php +++ b/app/Http/Controllers/Admin/MakerWorldController.php @@ -10,6 +10,7 @@ use App\Services\MakerWorldService; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Illuminate\View\View; class MakerWorldController extends Controller @@ -31,6 +32,22 @@ class MakerWorldController extends Controller $apiCollections = []; if ($tab === 'collections') { + // Check of actieve collecties toe zijn aan synchronisatie (> 5 minuten geleden of nog nooit gesynchroniseerd) + $dueCollections = MakerWorldCollection::where('is_active_sync', true) + ->where(function ($q) { + $q->whereNull('last_synced_at') + ->orWhere('last_synced_at', '<=', now()->subMinutes(5)); + }) + ->get(); + + foreach ($dueCollections as $dueCol) { + try { + $this->makerWorld->syncCollection($dueCol); + } catch (\Throwable $e) { + Log::warning("Auto-sync error for collection #{$dueCol->id}: {$e->getMessage()}"); + } + } + if ($isAuthenticated) { $apiCollections = $this->makerWorld->getFavoritesCollections(); } diff --git a/resources/views/admin/makerworld/index.blade.php b/resources/views/admin/makerworld/index.blade.php index 1c0142e..7593c24 100644 --- a/resources/views/admin/makerworld/index.blade.php +++ b/resources/views/admin/makerworld/index.blade.php @@ -304,8 +304,18 @@
Laatste controle: - + {{ $collection->last_synced_at ? $collection->last_synced_at->diffForHumans() : 'Nog niet' }} + @if($collection->last_synced_at) + ({{ $collection->last_synced_at->format('H:i:s') }}) + @endif + +
+
+ Auto-sync interval: + + + Iedere 5 min
@if($collection->last_sync_message) diff --git a/routes/console.php b/routes/console.php index d015ed8..a820c36 100644 --- a/routes/console.php +++ b/routes/console.php @@ -8,8 +8,8 @@ Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); -// Automatische MakerWorld Collecties Synchronisatie iedere 10 minuten +// Automatische MakerWorld Collecties Synchronisatie iedere 5 minuten Schedule::command('app:sync-makerworld-collections') - ->everyTenMinutes() + ->everyFiveMinutes() ->withoutOverlapping() ->runInBackground();