Skip to content

[9.x] Added the ability to use the uniqueFor method for Jobs#40974

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
andrey-helldar:patch/2022-02-12/13-08
Feb 12, 2022
Merged

[9.x] Added the ability to use the uniqueFor method for Jobs#40974
taylorotwell merged 1 commit into
laravel:9.xfrom
andrey-helldar:patch/2022-02-12/13-08

Conversation

@andrey-helldar

Copy link
Copy Markdown
Contributor

Currently, you can specify the duration of the job uniqueness check either by explicitly specifying the value in the variable, or by creating your own method, for example:

public function __constructor()
{
    $this->uniqueFor = $this->uniqueFor();
}

protected function uniqueFor()
{
    return now()->diffInRealSeconds($this->delay);
}

In my case, the job is created with a delayed start and there is a need to check the uniqueness during this time.

This means that you need to dynamically calculate the duration.

By adding the ability to use the "uniqueFor" method like the "uniqueId" method, we reduce the amount of code:

protected function uniqueFor()
{
    return now()->diffInRealSeconds($this->delay);
}

This will allow more flexible control over the uniqueness time.

@andrey-helldar andrey-helldar changed the title Added the ability to use the uniqueFor method for Jobs [9.x] Added the ability to use the uniqueFor method for Jobs Feb 12, 2022
@taylorotwell taylorotwell merged commit cd1bbe9 into laravel:9.x Feb 12, 2022
@andrey-helldar andrey-helldar deleted the patch/2022-02-12/13-08 branch February 12, 2022 18:30
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