How to have a strict order in queued listeners? Is this possible in Laravel?
up vote
0
down vote
favorite
Currently, I'm firing an event, when a user needs to be deleted. For example:
'AppEventsDeleteUserWasCalled' => [
'AppListenersUserDeleteUserImages',
'AppListenersUserRemoveFromMailchimp',
'AppListenersUserRemoveFromStripe',
'AppListenersUserRemoveOffers',
'AppListenersUserUpdateRelatedTablesToNull',
'AppListenersUserSoftDeleteUser',
],
All those listeners are implementing ShouldQueue. But my problem is that the queue is not in the correct order. For example 'AppListenersUserSoftDeleteUser' is processed before 'AppListenersUserRemoveFromMailchimp'.
RemoveFromMailchimpneeds the user's email but in SoftDeleteUser it is set to Null.
One solution comes into my mind is to use a job class and put everything in one class. But it feels not nice for me.
Any idea how to fix it? The order that I have listed is important (especially the last two listeners)
Edit
class DeleteUserWasCalled
{
use SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
laravel
|
show 1 more comment
up vote
0
down vote
favorite
Currently, I'm firing an event, when a user needs to be deleted. For example:
'AppEventsDeleteUserWasCalled' => [
'AppListenersUserDeleteUserImages',
'AppListenersUserRemoveFromMailchimp',
'AppListenersUserRemoveFromStripe',
'AppListenersUserRemoveOffers',
'AppListenersUserUpdateRelatedTablesToNull',
'AppListenersUserSoftDeleteUser',
],
All those listeners are implementing ShouldQueue. But my problem is that the queue is not in the correct order. For example 'AppListenersUserSoftDeleteUser' is processed before 'AppListenersUserRemoveFromMailchimp'.
RemoveFromMailchimpneeds the user's email but in SoftDeleteUser it is set to Null.
One solution comes into my mind is to use a job class and put everything in one class. But it feels not nice for me.
Any idea how to fix it? The order that I have listed is important (especially the last two listeners)
Edit
class DeleteUserWasCalled
{
use SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
laravel
Do you have access to the model id inside the listener? You could usewithTrashed()to get the soft deleted model
– Travis Britz
Nov 10 at 8:54
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes toNull. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.
– Shadrix
Nov 10 at 9:04
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
1
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Currently, I'm firing an event, when a user needs to be deleted. For example:
'AppEventsDeleteUserWasCalled' => [
'AppListenersUserDeleteUserImages',
'AppListenersUserRemoveFromMailchimp',
'AppListenersUserRemoveFromStripe',
'AppListenersUserRemoveOffers',
'AppListenersUserUpdateRelatedTablesToNull',
'AppListenersUserSoftDeleteUser',
],
All those listeners are implementing ShouldQueue. But my problem is that the queue is not in the correct order. For example 'AppListenersUserSoftDeleteUser' is processed before 'AppListenersUserRemoveFromMailchimp'.
RemoveFromMailchimpneeds the user's email but in SoftDeleteUser it is set to Null.
One solution comes into my mind is to use a job class and put everything in one class. But it feels not nice for me.
Any idea how to fix it? The order that I have listed is important (especially the last two listeners)
Edit
class DeleteUserWasCalled
{
use SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
laravel
Currently, I'm firing an event, when a user needs to be deleted. For example:
'AppEventsDeleteUserWasCalled' => [
'AppListenersUserDeleteUserImages',
'AppListenersUserRemoveFromMailchimp',
'AppListenersUserRemoveFromStripe',
'AppListenersUserRemoveOffers',
'AppListenersUserUpdateRelatedTablesToNull',
'AppListenersUserSoftDeleteUser',
],
All those listeners are implementing ShouldQueue. But my problem is that the queue is not in the correct order. For example 'AppListenersUserSoftDeleteUser' is processed before 'AppListenersUserRemoveFromMailchimp'.
RemoveFromMailchimpneeds the user's email but in SoftDeleteUser it is set to Null.
One solution comes into my mind is to use a job class and put everything in one class. But it feels not nice for me.
Any idea how to fix it? The order that I have listed is important (especially the last two listeners)
Edit
class DeleteUserWasCalled
{
use SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
laravel
laravel
edited Nov 10 at 9:37
asked Nov 10 at 8:43
Shadrix
414313
414313
Do you have access to the model id inside the listener? You could usewithTrashed()to get the soft deleted model
– Travis Britz
Nov 10 at 8:54
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes toNull. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.
– Shadrix
Nov 10 at 9:04
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
1
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24
|
show 1 more comment
Do you have access to the model id inside the listener? You could usewithTrashed()to get the soft deleted model
– Travis Britz
Nov 10 at 8:54
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes toNull. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.
– Shadrix
Nov 10 at 9:04
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
1
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24
Do you have access to the model id inside the listener? You could use
withTrashed() to get the soft deleted model– Travis Britz
Nov 10 at 8:54
Do you have access to the model id inside the listener? You could use
withTrashed() to get the soft deleted model– Travis Britz
Nov 10 at 8:54
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes to
Null. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.– Shadrix
Nov 10 at 9:04
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes to
Null. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.– Shadrix
Nov 10 at 9:04
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
1
1
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24
|
show 1 more comment
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237363%2fhow-to-have-a-strict-order-in-queued-listeners-is-this-possible-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237363%2fhow-to-have-a-strict-order-in-queued-listeners-is-this-possible-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have access to the model id inside the listener? You could use
withTrashed()to get the soft deleted model– Travis Britz
Nov 10 at 8:54
@TravisBritz yes I have the id and I can get the trashed model, but in SoftDeleteUser I'm not only soft-deleting the user but I set all attributes to
Null. So it does not matter, I won't get the right email. Of course, I could copy the email in the event class, but I'm interested in a better way.– Shadrix
Nov 10 at 9:04
If you're deleting data that you'll need later, you should either pass that data to the event or wait to delete it. For example, you could have a scheduled task for setting attributes to null which runs regularly and clears records where deleted_at is older than an hour
– Travis Britz
Nov 10 at 9:07
@TravisBritz hmm I like the idea with a scheduled task. However, technically the GDPR writes the information should be deleted immediately (I live in Germany...). Besides that, it would be cool to delete the data as soon as possible, since the user might want to create a new account with the same email but in the DB email is set to unique.
– Shadrix
Nov 10 at 9:17
1
In that case passing the user data directly to the event might be the best option, and your listeners can get the user data from the event payload rather than from the database
– Travis Britz
Nov 10 at 9:24