-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Description
Considering the following example in the documentation :
// the frequency can be defined as an integer representing the number of seconds
#[AsPeriodicTask(frequency: 86400)]
// adds randomly up to 6 seconds to the trigger time to avoid load spikes
#[AsPeriodicTask(frequency: '1 day', jitter: 6)]
// defines the method name to call instead as well as the arguments to pass to it
#[AsPeriodicTask(frequency: '1 day', method: 'sendEmail', arguments: ['email' => 'admin@symfony.com'])]
class SendDailySalesReports
{
public function sendEmail(string $email): void
{
// ...
}
}
// defines the timezone to use
#[AsPeriodicTask(frequency: '1 day', timezone: 'Africa/Malabo')]
It looks like we can use a timezone
parameter on AsPeriodicTask
attribute to force a given timezone.
However, the attribute does not implement this feature (at least not through a timezone
parameter) :
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class AsPeriodicTask
{
/**
* @param string|int $frequency A string (i.e. "every hour") or an integer (the number of seconds) representing the frequency of the task
* @param string|null $from A string representing the start time of the periodic task (i.e. "08:00:00")
* @param string|null $until A string representing the end time of the periodic task (i.e. "20:00:00")
* @param int|null $jitter The cron jitter, in seconds; for example, if set to 60, the cron
* will randomly wait for a number of seconds between 0 and 60 before
* executing which allows to avoid load spikes that can happen when many tasks
* run at the same time
* @param array<array-key, mixed>|string|null $arguments The arguments to pass to the cron task
* @param string $schedule The name of the schedule responsible for triggering the task
* @param string|null $method The method to run as the task when the attribute target is a class
* @param string[]|string|null $transports One or many transports through which the message scheduling the task will go
*/
public function __construct(
public readonly string|int $frequency,
public readonly ?string $from = null,
public readonly ?string $until = null,
public readonly ?int $jitter = null,
public readonly array|string|null $arguments = null,
public readonly string $schedule = 'default',
public readonly ?string $method = null,
public readonly array|string|null $transports = null,
) {
}
}
I think AsPeriodicTask
attribute should implement this timezone
parameter like AsCronTask
attribute does in this example :
// adds randomly up to 6 seconds to the trigger time to avoid load spikes
#[AsCronTask('0 0 * * *', jitter: 6)]
// defines the method name to call instead as well as the arguments to pass to it
#[AsCronTask('0 0 * * *', method: 'sendEmail', arguments: ['email' => 'admin@example.com'])]
// defines the timezone to use
#[AsCronTask('0 0 * * *', timezone: 'Africa/Malabo')]
This is implemented for AsCronTask
.
viapinotvaltzu