Skip to content

Commit

Permalink
Migrate away from using job system to trigger background task to reta…
Browse files Browse the repository at this point in the history
…in cross-version compatibility (#333)
  • Loading branch information
cassidydotdk authored Feb 10, 2019
1 parent 992cba9 commit 1448308
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Linq;
using System.Threading;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Serialization;
using Sitecore.Diagnostics;
using Sitecore.Eventing;
using Sitecore.Jobs;
using Sitecore.Sites;
using Unicorn.Predicates;

// ReSharper disable UnusedMember.Global
Expand All @@ -31,16 +32,23 @@ protected virtual void DeserializationComplete(string databaseName)
Assert.ArgumentNotNullOrEmpty(databaseName, "databaseName");

// raising this event can take a long time. like 16 seconds. So we boot it as a job so it can go in the background.
Job asyncSerializationFinished = new Job(new JobOptions("Raise deserialization complete async", "serialization", "shell", this, "RaiseEvent", new object[] { databaseName }));
JobManager.Start(asyncSerializationFinished);

Log.Info($"Job started: Raise deserialization complete async ({typeof(SendSerializationCompleteEvent).FullName})", this);
ThreadPool.QueueUserWorkItem(RaiseEvent, databaseName);
}

public virtual void RaiseEvent(string databaseName)
public virtual void RaiseEvent(object state)
{
EventManager.RaiseEvent(new SerializationFinishedEvent());
Database database = Factory.GetDatabase(databaseName, false);
using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
{
var databaseName = state.ToString();
EventManager.RaiseEvent(new SerializationFinishedEvent());
Database database = Factory.GetDatabase(databaseName, false);

database?.RemoteEvents.Queue.QueueEvent(new SerializationFinishedEvent());
}

database?.RemoteEvents.Queue.QueueEvent(new SerializationFinishedEvent());
Log.Info($"Job ended: Raise deserialization complete async ({typeof(SendSerializationCompleteEvent).FullName})", this);
}
}
}

0 comments on commit 1448308

Please sign in to comment.