llaski / nova-scheduled-jobs

Nova Scheduled Jobs
MIT License
54 stars 19 forks source link

[BUG]: JavaScript Error on load #49

Open kaiserkiwi opened 1 year ago

kaiserkiwi commented 1 year ago

Description of the bug

image

I just installed this Package into my configured Nova installation and wanted to try it out. Sadly I alway get an JavaScript-Error. The message implies, that the jobs variable is undefined. But my jobs run totally fine. So I really don't have any idea what I could do. The installation process is not really complicated and I made exactly the same with the Nova Queues Package.

The error is on the single page and on the card aswell.

Steps To Reproduce

  1. Follow installation instructions.
  2. Go to your nova route.
  3. Open the Dev-Tools
  4. See the error

Additional Information

Plugin-Version: 6.0.1 Laravel-Version: 9.43.0 Nova-Version: 4.19.4 PHP-Verison: 8.1.12 Packages that could interfere: https://github.com/den1n/nova-queues

llaski commented 1 year ago

@kaiserkiwi I was not able to reproduce this with the same versions you listed. It's possible there is an issue with what the endpoint is returning based on the events you have scheduled, either a bug or use case this package doesn't currently handle. Can you share your Console/Kernel.php file and check if the server is returning a valid response for the endpoint that returns the jobs?

kaiserkiwi commented 1 year ago

Sure. Here ist my Console/Kernel.php nothing wild.

<?php

namespace App\Console;

use App\Actions\Questlog\Fetch\FetchGames;
use App\Actions\Questlog\Fetch\FetchGenres;
use App\Actions\Questlog\Fetch\FetchPlatforms;
use App\Actions\Questlog\Fetch\UpdateGames;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        FetchGames::class,
        FetchGenres::class,
        FetchPlatforms::class,
        UpdateGames::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param Schedule $schedule
     *
     * @return void
     */
    protected function schedule(Schedule $schedule): void
    {
         $schedule->command('fetch:platforms')->daily();
         $schedule->command('fetch:genres')->daily();
         $schedule->command('update:games')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}

And this is the response from the jobs endpoint:

[
  {
    "command": "php artisan fetch:platforms",
    "description": "",
    "expression": "0 0 * * *",
    "expressionHumanReadable": "At 00:00 on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-09 00:00:00 +00:00",
    "nextDueHumanReadable": "in 14 Stunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  },
  {
    "command": "php artisan fetch:genres",
    "description": "",
    "expression": "0 0 * * *",
    "expressionHumanReadable": "At 00:00 on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-09 00:00:00 +00:00",
    "nextDueHumanReadable": "in 14 Stunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  },
  {
    "command": "php artisan update:games",
    "description": "",
    "expression": "* * * * *",
    "expressionHumanReadable": "Every minute on every day.",
    "timezone": "UTC",
    "nextDue": "2022-12-08 09:24:00 +00:00",
    "nextDueHumanReadable": "in 15 Sekunden",
    "withoutOverlapping": false,
    "onOneServer": false,
    "runInBackground": false,
    "evenInMaintenanceMode": false
  }
]
llaski commented 1 year ago

@kaiserkiwi So that response is interesting - it's actually missing a level of nesting. It should be:

{
   "data":[
      {
         "command":"php artisan fetch:platforms",
         "description":"",
         "expression":"0 0 * * *",
         "expressionHumanReadable":"At 00:00 on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-09 00:00:00 +00:00",
         "nextDueHumanReadable":"in 14 Stunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      },
      {
         "command":"php artisan fetch:genres",
         "description":"",
         "expression":"0 0 * * *",
         "expressionHumanReadable":"At 00:00 on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-09 00:00:00 +00:00",
         "nextDueHumanReadable":"in 14 Stunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      },
      {
         "command":"php artisan update:games",
         "description":"",
         "expression":"* * * * *",
         "expressionHumanReadable":"Every minute on every day.",
         "timezone":"UTC",
         "nextDue":"2022-12-08 09:24:00 +00:00",
         "nextDueHumanReadable":"in 15 Sekunden",
         "withoutOverlapping":false,
         "onOneServer":false,
         "runInBackground":false,
         "evenInMaintenanceMode":false
      }
   ]
}

That is prob the culprit here - do you have any custom middleware or do any customization to the collection resource wrapper?

kaiserkiwi commented 1 year ago

That could be the problem. I have the line JsonResource::withoutWrapping(); in my AppServiceProvider for some specific reasons.

Would it be possible to alter your package to catch this edge case or should I try to rework my code to get it working?

kaiserkiwi commented 1 year ago

Hi, I'm finally back on my Notebook. If I comment out JsonResource::withoutWrapping(); then it instantly works. As that's something that is mentioned in the docs (https://laravel.com/docs/9.x/eloquent-resources#data-wrapping) I would guess my project is not the only one that uses it.

So it would be awesome, if you could catch this edge case.

kaiserkiwi commented 1 year ago

Any news an this? 🙂

llaski commented 1 year ago

@kaiserkiwi I don't have time to currently address this but feel free to open a PR. Will see if I can review in the next month or two.

devnicolas1 commented 1 year ago

Do we have any news on this? @llaski I can totally open a PR with a fix, but my lack of knowledge/experience makes a bit difficult for me to debug the code. Can you help me with a general idea of what might be causing the bug? Anything would help. I can continue after that.

Also @kaiserkiwi would be great to know if you found any workaround this

kaiserkiwi commented 1 year ago

I sadly hadn't the time to research this further. As far as I remember the error was in the reaponse part of the AJAX request. The wrapping data is expected and it comes to an error.

As I will switch to Filament (because of the stagnation of Nova) I probably won't research this anymore even if I have the time. Sorry.

devnicolas1 commented 1 year ago

Thats totally okay! Thanks anyway :)

llaski commented 1 year ago

@devnicolas1 @kaiserkiwi I also have not had much time to look into this. I did spend a few minutes on seeing if there was an easy way to fix this but requires more investigation/though on how to resolve this.

@kaiserkiwi @devnicolas1 I'm not familiar with filament but have seen v3 was released and it seems to be very popular. Do you know if filament has a package that handles what this package does already? If not may look at learning filament and porting this over.

devnicolas1 commented 1 year ago

@llaski I have no knowledge/experience with Filament, but it does look pretty cool. I'll be putting my hands into it soon, and I'll let you know if I find any alternative to this package :)

kaiserkiwi commented 1 year ago

@llaski Looks like this is a similar package for Filament: https://filamentphp.com/plugins/husam-database-schedule