0

I have a job class called NotifyUsersJob this class, of course, implements shouldQueue interface which is the default queue class that Laravel gives me. In the handle method, I have this logic.

Notification::send($this->users, new NotifyUser($this->message));

In NotifyUser notification class I send the notification throw WebPushChannel. My question is about should I implement shouldQueue in NotifyUser class also or not, and if I should do that why? By the way, everything is working fine both are working well, but I would like to know the right way of doing this.

4

1 回答 1

1

It depends on what you are trying to achieve. If you want to run the notification in background then yes. Using should queue will create a job that gets processed in the background such that you do not have to wait till it gets processed.

But if you think your application might break down at some point then you will not be able to get the error then and there. you will have to extract from failed job table if using database for queue. So my catch would be.

  1. If you think your notification can take some time to process use shouldqueue such that it runs in the background and your application dosent lag behind
  2. If you think you need to get errors instantly if the notification did not work then dont use shouldQueue
于 2020-01-21T19:35:34.313 回答