Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger][Scheduler] Add AsCronTask & AsPeriodicTask attributes#51525

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromvaltzu:51432-scheduler-improvements
Oct 1, 2023

Conversation

valtzu
Copy link
Contributor

@valtzuvaltzu commentedAug 31, 2023
edited
Loading

QA
Branch?6.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#51432
LicenseMIT
Doc PRsymfony/symfony-docs#...// todo

Simplify scheduler usage by allowing to declare an attributeAsCronTask /AsPeriodicTask on any registered & autoconfigured service.

Example usage:

#[AsPeriodicTask(frequency:5, jitter:1, arguments: ['Hello from periodic trigger'])]class BusinessLogic{publicfunction__invoke(string$message):void    {echo"$message\n";    }}
#[AsCronTask('* * * * *', arguments:'hello -v')]#[AsCommand('app:do-stuff')]class DoStuffCommandextends Command{// ...}
services:some_other_service:class:# ...tags:      -name:scheduler.tasktrigger:cronexpression:'0 9-17 * * *'method:'someMethod'transports:[async]

bin/console debug:schedule output:

Scheduler=========default------- ------------------------------------------- ---------------------------------------- ---------------------------------   Message                                     Trigger                                  Next Run                          ------------------------------------------- ---------------------------------------- ---------------------------------   @App\BusinessLogic                          every 5 seconds with 0-1 second jitter   Sat, 02 Sep 2023 10:55:36 +0000    app:do-stuff hello -v*****                                Sat, 02 Sep 2023 13:56:00 +0300    @some_other_service::someMethod via async   0 9-17***                             Sat, 02 Sep 2023 14:00:00 +0300   ------------------------------------------- ---------------------------------------- ---------------------------------

And then runbin/console messenger:consume scheduler_default to run the scheduler, like the usual.


To-do (help needed):

  1. tests
  2. docs
  3. validate the approach (creatingRecurringMessages using DI)

vtsykun, andreybolonin, ChrisRiddell, and ERuban reacted with rocket emoji
@valtzuvaltzu requested a review fromkbond as acode ownerAugust 31, 2023 14:23
@carsonbotcarsonbot added this to the6.4 milestoneAug 31, 2023
@valtzuvaltzuforce-pushed the51432-scheduler-improvements branch 3 times, most recently fromfd2967e tod6a2819CompareAugust 31, 2023 19:01
@valtzuvaltzu changed the title[Messenger] Add AsCronTask & AsPeriodicTask attributes[Scheduler][Messenger] Add AsCronTask & AsPeriodicTask attributesAug 31, 2023
@valtzuvaltzu changed the title[Scheduler][Messenger] Add AsCronTask & AsPeriodicTask attributes[Scheduler] Add AsCronTask & AsPeriodicTask attributesAug 31, 2023
@valtzu
Copy link
ContributorAuthor

What could also be a cool feature here is addtransports property to both attributes/tags, then if it is set, wrapServiceCallMessage inRedispatchMessage.

kbond reacted with thumbs up emoji

@kbond
Copy link
Member

This looks nice! I'll give a proper review and help finish up for 6.4 when I have some time.

What are you thinking for commands? I was thinking:

#[AsCronTask(expression:'* * * * *', arguments:'arg --option')]class MyCommandextends Command{}
valtzu reacted with thumbs up emoji

@valtzu
Copy link
ContributorAuthor

valtzu commentedSep 2, 2023
edited
Loading

What are you thinking for commands?

I was hoping we don't need such, as business logic usually is wrapped in a separate class and commands just act as an entry point, just like controllers. But I think this is only my reality.

About the attribute syntax for commands,ArrayInput syntax was my first thought, but I seeRunCommandMessage uses string input so probably your suggestion makes the most sense if the approach would be to produce those instead ofServiceCallMessage. AlsoStringInput syntax is less verbose and since the whole point here is to make thing easier, that's the way to go then.

@kbond
Copy link
Member

Looking good! Glad you got commands working - usingRunCommandMessage is exactly what I was thinking.

valtzu reacted with thumbs up emoji

@valtzuvaltzuforce-pushed the51432-scheduler-improvements branch from6341a0a tocd499eeCompareSeptember 13, 2023 16:23
@valtzu
Copy link
ContributorAuthor

valtzu commentedSep 14, 2023
edited
Loading

I didn't realize it's possible to useRedispatchMessage without explicitly defining the transports (and rely onrouting configuration), we need to add support for that also. Probably renametransports toredispatch and allow boolean.

Hmm, ok it does not seem possible after all, if transportNames are not defined, then the message is not dispatched to any transport – unlike the Messenger docs are stating.

@carsonbotcarsonbot changed the title[Scheduler] Add AsCronTask & AsPeriodicTask attributes[Messenger][Scheduler] Add AsCronTask & AsPeriodicTask attributesSep 26, 2023
@fabpotfabpotforce-pushed the51432-scheduler-improvements branch fromcd499ee toed27b20CompareOctober 1, 2023 08:32
@fabpot
Copy link
Member

Thank you@valtzu.

@@ -10,6 +10,9 @@ services:
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummySchedule:
autoconfigure: true

Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTask:
autoconfigure: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There are no tests associated with this, can you add some@valtzu?
I've moved these to a new schedule to avoid breaking the existing tests (#51802).

valtzu reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@fabpot I'm not too familiar with the framework tests yet, and I'm also a bit busy now. I would need a week or two, if that's ok then I can try.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure, there is no rush. Ping me if you need help.

fabpot added a commit that referenced this pull requestNov 3, 2023
… schedule (valtzu)This PR was merged into the 6.4 branch.Discussion----------[FrameworkBundle][Scheduler] Add test for autoconfigured schedule| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| License       | MITAdd functional tests for autoconfigured schedules / tasks, as discussed in#51525 (comment).Commits-------ea2a8cd Add test for autoconfigured schedule
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull requestNov 3, 2023
… schedule (valtzu)This PR was merged into the 6.4 branch.Discussion----------[FrameworkBundle][Scheduler] Add test for autoconfigured schedule| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| License       | MITAdd functional tests for autoconfigured schedules / tasks, as discussed insymfony/symfony#51525 (comment).Commits-------ea2a8cd7255 Add test for autoconfigured schedule
@faizanakram99
Copy link
Contributor

faizanakram99 commentedJan 4, 2024
edited
Loading

@valtzu@kbond iiuc, this doesn't support stateful schedules (equivalent to$schedule->stateful($cache)), right?

nvm, it will only add tasks to given schedule (and schedule can be optionally be stateful)

kbond reacted with thumbs up emoji

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestJan 22, 2025
… Symfony command (W0rma)This PR was merged into the 6.4 branch.Discussion----------[Scheduler] Add example about how to pass arguments to a Symfony commandWe recently wanted to pass arguments to a Symfony command which is configured for the scheduler component with the `#[AsPeriodicTask]` attribute.The syntax mentioned insymfony/symfony#51525 (comment) worked.This PR adds an example to the docs.Commits-------fc90d83 [Scheduler] Add example about how to pass arguments to a Symfony command
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

@kbondkbondAwaiting requested review from kbondkbond is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

[RFC][Scheduler] Simplify schedule usage
5 participants
@valtzu@kbond@fabpot@faizanakram99@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp