Skip to content

[RFC][Scheduler] Simplify schedule usage  #51432

Closed
@vtsykun

Description

@vtsykun

Description

Currently, it takes a lot of effort to create a scheduled task.

  • define schedule provider
  • create a message class
  • create a messenger handler.

These steps look too redundant, if you need to create a couple of simple tasks such as cleaning archive dir, check users, etc.

Proposal

To simplify using of the scheduled tasks, proposed add AsPeriodicTask and AsCronTask attributes. They can be added as class or method attributes to any symfony service or console command.

Additionally, it is need to allow the merging of scheduled tasks obtained from schedule providers with the same name.

#[AsPeriodicTask('1 day')]

#[AsCronTask('35,45,55 */3 * * *', jitter: 60, arguments: ['level' => '500mb'])]

#[AsCronTask('@random 3600', schedule: 'default')]

Example

<?php declare(strict_types=1);

namespace App\Service;

#[AsCronTask('*/5 * * * *')]
class SyncAppWorker
{
    public function __invoke(array $arguments = []): void
    {
        // code
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)Scheduler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions