app.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. use App\Http\Middleware\CheckPermission;
  3. use App\Http\Middleware\EnsureProviderIsAccepted;
  4. use App\Http\Middleware\PerformanceMonitor;
  5. use App\Http\Middleware\SetUserLanguage;
  6. use App\Tasks\DeleteExpiredTokens;
  7. use App\Tasks\SendPushNotificationsTask;
  8. use Illuminate\Console\Scheduling\Schedule;
  9. use Illuminate\Foundation\Application;
  10. use Illuminate\Foundation\Configuration\Exceptions;
  11. use Illuminate\Foundation\Configuration\Middleware;
  12. use Illuminate\Support\Facades\Log;
  13. use Laravel\Sanctum\Http\Middleware\CheckForAnyAbility;
  14. return Application::configure(basePath: dirname(__DIR__))
  15. ->withRouting(
  16. web: __DIR__.'/../routes/web.php',
  17. api: __DIR__.'/../routes/api.php',
  18. commands: __DIR__.'/../routes/console.php',
  19. health: '/up',
  20. )
  21. ->withMiddleware(function (Middleware $middleware) {
  22. // $middleware->statefulApi();
  23. $middleware->append([SetUserLanguage::class, PerformanceMonitor::class]);
  24. $middleware->alias([
  25. 'permission' => CheckPermission::class,
  26. 'ability' => CheckForAnyAbility::class,
  27. 'provider.accepted' => EnsureProviderIsAccepted::class,
  28. ]);
  29. })
  30. ->withSchedule(function (Schedule $schedule) {
  31. $schedule->call(new DeleteExpiredTokens)->everyMinute();
  32. $sendPushNotifications = function () {
  33. try {
  34. app(SendPushNotificationsTask::class)();
  35. } catch (Throwable $e) {
  36. Log::error('Falha ao resolver SendPushNotificationsTask: '.$e->getMessage(), [
  37. 'exception' => $e,
  38. ]);
  39. }
  40. };
  41. $schedule->call($sendPushNotifications)->dailyAt('08:00');
  42. $schedule->call($sendPushNotifications)->dailyAt('13:00');
  43. $schedule->call($sendPushNotifications)->dailyAt('19:00');
  44. })
  45. ->withExceptions(function (Exceptions $exceptions) {
  46. //
  47. })
  48. ->create();