I have a document type that has a property called revision number, on existing documents when the revision number property is changed, i am using the saving event of the content service to catch when the document type has changed and the property is dirty.
At that point i can do a lookup for matching records and then send out emails, potentially searching though many records and sending many items will take a while and will cause a delay in showing the green save success banner in the backoffice.
This is a snippet of the code, i have tried to spawn a background thread for the lookups and sending however this does not seem to make any difference.
void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
{
foreach (IContent node in e.SavedEntities)
{
if (node.ContentType.Alias == "x")
{
if (node.HasIdentity && node.IsPropertyDirty("revisionNumber"))
{
//Do lookups
SendEmail(emailAddress);
}
}
}
}
hmm, it's difficult to know what is involved in your lookup process, but perhaps an idea here would be instead of doing the lookup work inside the event; to just instead use your Saving event 'hook in' above to write the Id, RevisionNumber and Timestamp to a database table.
Then have a separate background task (windows service, or console app or scheduled task etc) polling the database table - reading the ids and revision numbers and doing the lookups for each row, sending emails etc, and then marking the row in the table as 'looked
I found moving my code to saved and running my lookup in a background thread seems to solve the immediate issue i was having.
Doing the background thread in saving seemed to not create the delay and runs pretty quick
However i know that the background thread is not the safest option and would look at having a service or something poll.
The lookups were basically though all the invoices in merchello that contains a product that had been updated and sends a mail to each customer saying it was updated.
Content service saving run a background task
Hi,
I have a document type that has a property called revision number, on existing documents when the revision number property is changed, i am using the saving event of the content service to catch when the document type has changed and the property is dirty.
At that point i can do a lookup for matching records and then send out emails, potentially searching though many records and sending many items will take a while and will cause a delay in showing the green save success banner in the backoffice.
This is a snippet of the code, i have tried to spawn a background thread for the lookups and sending however this does not seem to make any difference.
Is there a better way to achieve this?
Thanks
Paul
Hi Paul
hmm, it's difficult to know what is involved in your lookup process, but perhaps an idea here would be instead of doing the lookup work inside the event; to just instead use your Saving event 'hook in' above to write the Id, RevisionNumber and Timestamp to a database table.
Then have a separate background task (windows service, or console app or scheduled task etc) polling the database table - reading the ids and revision numbers and doing the lookups for each row, sending emails etc, and then marking the row in the table as 'looked
Like a rudimentary service bus queue: https://azure.microsoft.com/en-gb/documentation/articles/service-bus-dotnet-how-to-use-queues/#what-are-service-bus-queues
and your backoffice update would save quickish...
Hi Marc,
I found moving my code to saved and running my lookup in a background thread seems to solve the immediate issue i was having.
Doing the background thread in saving seemed to not create the delay and runs pretty quick
However i know that the background thread is not the safest option and would look at having a service or something poll.
The lookups were basically though all the invoices in merchello that contains a product that had been updated and sends a mail to each customer saying it was updated.
is working on a reply...