0

I have a queue. After completing all the tasks, I would like to execute the function. Example

Queue: Task1 Task2 Task3 Task4 Task5

Here, when queue is empty, we have to run Function. The documentation only has an event that fires after every task.

3
  • The queue is not designed to work in such a manner, theoretically the queue can be full for a long time if multiple jobs queue up. If you have database rows associated with it an flag like is_done and an event to check if all the associated rows has been ranned is the correct approach in my opinion. Commented May 18, 2021 at 7:25
  • @mrhn I am importing data via a queue, then I need to sort it Commented May 18, 2021 at 7:36
  • @mrhn I found this stackoverflow.com/questions/41228745/… Commented May 18, 2021 at 7:41

1 Answer 1

1

Hey Alex you could work with Livewire and request all 3 sec if the table jobs is empty. when the table is empty you can then fire a function.

Livewire Controller:

public string $filename;
public mixed $errorlist = [];
public bool $showLoadSequence = True;

public function getError()
{
    // check if job table is empy
    if (!DB::table('jobs')->exists() && $this->showLoadSequence === True) {
        $this->showLoadSequence = False;
        // call to action!
    }

    $errors = ValidationResult::where('file_name', '=', $this->filename)
        ->where('isValid', false)
        ->get();

    if (count($errors) !== count($this->errorlist)) {
        $this->errorlist = $errors;
    }
}

public function render()
{
    return view('livewire.error-loader');
}

Live wire blade:

<div wire:poll.3s="getError">
 //html tags
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.