Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'. #53673

Closed
rcerljenko opened this issue Nov 26, 2024 · 7 comments

Comments

@rcerljenko
Copy link

rcerljenko commented Nov 26, 2024

Laravel Version

11.34.0

PHP Version

8.3.14

Database Driver & Version

No response

Description

Hi,

With the latest update, schedule grouping throws an Exception when using job method.

@istiak-tridip you will probably be the first to know what's going on.

 LogicException 

  A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'.

  at vendor\laravel\framework\src\Illuminate\Console\Scheduling\CallbackEvent.php:142
    138▕      */
    139▕     public function withoutOverlapping($expiresAt = 1440)
    140▕     {
    141▕         if (! isset($this->description)) {
  ➜ 142▕             throw new LogicException(
    143▕                 "A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'."
    144▕             );
    145▕         }

Steps To Reproduce

<?php

// routes/console.php

use Illuminate\Support\Facades\Schedule;
use Illuminate\Console\Scheduling\Schedule as ConsoleSchedule;

Schedule::onOneServer()
	->runInBackground()
	->withoutOverlapping()
	->group(static function (ConsoleSchedule $schedule): void {
		// HOURLY
		$schedule->hourly()
			->group(static function (ConsoleSchedule $schedule): void {
				$schedule->job(new SomeJobClass);
			});
	});
@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@rcerljenko
Copy link
Author

HI, I simplified the "Steps To Reproduce". The "when" is not important at all. It fails with a simple job definition.

@istiak-tridip
Copy link
Contributor

Thanks for reporting the issue, @rcerljenko.

The problem arises from the combination of the withoutOverlapping and job methods. The job method uses the call method under the hood, which requires a name when paired with withoutOverlapping. In schedule groups, the withoutOverlapping attribute is being applied without a name/description attribute, leading to the issue. I’ll work on submitting a fix.

@rcerljenko
Copy link
Author

Many thanks @istiak-tridip ! :)

@rcerljenko
Copy link
Author

Hi @istiak-tridip ,

With the latest update we moved from one exception to antoher.
Using the same schedule definitions it now throws this:

  RuntimeException 

  Scheduled closures can not be run in the background.

  at vendor\laravel\framework\src\Illuminate\Console\Scheduling\CallbackEvent.php:105
    101▕      * @throws \RuntimeException
    102▕      */
    103▕     public function runInBackground()
    104▕     {
  ➜ 105▕         throw new RuntimeException('Scheduled closures can not be run in the background.');
    106▕     }

@istiak-tridip
Copy link
Contributor

@rcerljenko This is expected behavior. Flattening your schedule group would result in:

Schedule::job(new SomeJobClass)
    ->hourly()
    ->onOneServer()
    ->runInBackground()
    ->withoutOverlapping();

This throws an exception on runInBackground() because job cannot run in the background. The issue lies with the job event’s limitations, not the Schedule Group itself.

@rcerljenko
Copy link
Author

Hi,

Ok makes sense... thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants