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

[11.x] Add make:job-middleware artisan command #52965

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

dshafik
Copy link

@dshafik dshafik commented Sep 27, 2024

This PR adds a new make:job-middleware artisan command that will create a new Job Middleware class in App\Jobs\Middleware. This stub is based on the docs.

One other minor change is to update the description for make:middleware to clarify it creates HTTP middleware.

An alternative to this would be to add --job flag to make:middleware that will conditionally create a Job middleware instead of HTTP middleware (could also add a corresponding --http flag just for completeness sake) — let me know if that is preferred.

@devajmeireles
Copy link
Contributor

That's cool, but I'm wondering if we can't simply adapt make:middleware to ask what kind of middleware we want to create?

@dshafik
Copy link
Author

dshafik commented Sep 27, 2024

That's cool, but I'm wondering if we can't simply adapt make:middleware to ask what kind of middleware we want to create?

That's what I suggested as an alternative in the PR description (make:middleware --job). My main concern is that the MiddlewareMakeCommand is in the \Illuminate\Routing\Console namespace where the Job middleware stuff arguably does not belong. Are there any other commands that cross multiple concerns like this?

@devajmeireles
Copy link
Contributor

That's cool, but I'm wondering if we can't simply adapt make:middleware to ask what kind of middleware we want to create?

That's what I suggested as an alternative in the PR description (make:middleware --job). My main concern is that the MiddlewareMakeCommand is in the \Illuminate\Routing\Console namespace where the Job middleware stuff arguably does not belong. Are there any other commands that cross multiple concerns like this?

Although you're right, you can still implement this logic if you check if something related to queues was loaded, for example the ShouldQueue interface. If yes, you can display a selection - to select the middleware type, after insert the middleware name in the make:middleware command.

@dshafik
Copy link
Author

dshafik commented Sep 28, 2024

@devajmeireles what are you thinking of checking for the ShouldQueue interface? During the execution of the artisan command there are no jobs loaded or anything…

@devajmeireles
Copy link
Contributor

@devajmeireles what are you thinking of checking for the ShouldQueue interface? During the execution of the artisan command there are no jobs loaded or anything…

You had mentioned: "MiddlewareMakeCommand is in the \Illuminate\Routing\Console namespace where the Job middleware stuff arguably does not belong.". To resolve this, you can check if something related to queues exists - I used ShouldQueue as an example, if it does then we can generate a middleware for jobs using make:middleware.

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

Successfully merging this pull request may close these issues.

2 participants