Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Jul 17, 2023 @ 14:02
    Jay
    0

    Hangfire Content Service on Load Balancing setup

    Hi all,

    I'm having an issue with Content Service Save and Published being called using Hangfire on the Master server which only updates the master.

    The content doesn't gets triggered or updated for the remaining Slaves not sure why.

    Anyone have any idea?

    Thank you

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jul 23, 2023 @ 14:35
    Marc Goodson
    0

    Hi Jay

    I have had possibly similar to this happen on a V7 site before.

    What was happening for me was when I called contentService.SaveAndPublishWithStatus() within my hangfire task, the cache refreshing instructions created by this action were being stored temporarily in 'HttpContext.Items' - Normally if publishing from Umbraco, the BatchedDatabaseServerMessenger handles reading these items and inserting them into the Database, but because Hangfire runs in a background thread without a context, we were faking an UmbracoContext and the instructions were being lost.

    We were able to work around this by manually calling FlushBatch() on the BatchedDatabaseServerMessenger from within the Hangfire task:

    contentService.SaveAndPublishWithStatus(twitterApiSettings);
    
                        // In a hangfire task the SaveAndPublishWithStatus isn't raising the cache refreshing events, this appears to be a way to flush the instructions into the db?
                        BatchedDatabaseServerMessenger bdsMess = ServerMessengerResolver.Current.Messenger as BatchedDatabaseServerMessenger;
                        bdsMess.FlushBatch();
    

    Now this was V7, so I'm not sure if this will be the same in V8, or if the BatchedDatabaseServerManager exists in V8, or if the same workaround would work... :-P

    (looks like it exists in V8: https://github.com/umbraco/Umbraco-CMS/blob/v8/dev/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs#L26C18-L26C48 but you might need to inject the BatchedDatabaseServerMessenger in to get reference to it)

    But you were asking if anyone had an idea, and this might be the sort of thing that is the cause!!

    Hope it helps steer you to a solution.

    regards

    marc

  • Jay 425 posts 652 karma points
    Jul 25, 2023 @ 08:49
    Jay
    0

    thanks Marc I'll try it out

Please Sign in or register to post replies

Write your reply to:

Draft