Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul 25 posts 75 karma points
    Aug 20, 2015 @ 15:10
    Paul
    0

    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.

    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);
                }
            }
        }
    }
    

    Is there a better way to achieve this?

    Thanks

    Paul

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Aug 23, 2015 @ 00:02
    Marc Goodson
    0

    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...

  • Paul 25 posts 75 karma points
    Aug 26, 2015 @ 12:11
    Paul
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft