I have a requirement to invalidate the file in cdn cache on completion of sitecore item publishing. To achieve this I have created custom processor and patched into "publishEndResultBatch" pipeline, my patches are displaying in showconfig. But the code is not triggered, I have debugged and added logs, no symbol to trigger this processor.
I have even created custom event handler and patched in "publishingservice:publishend" event. This is also not triggered.
No issue in item publish.
Is it need any additional settings to use the custom events or processor in sitecore publishing service?
Below are the package details,
- Instance
- Sitecore 9 update 1
- Sitecore Publishing Service
- Sitecore Publishing Module 3.1.1 rev. 180807.zip
- Sitecore Publishing Service 3.1.1 rev. 180807-x64.zip
Below are the code snippet
Custom processor:
public class CustomPublishEndResultBatch
{
Log4NetLogger _logger = new Log4NetLogger();
public void Process(PublishEndResultBatchArgs args)
{
_logger.Log("publishEndResult Batch", EnumUtil.LoggingType.Info, EnumUtil.ExceptionTier.PublishingService, null);
try
{
if (args.TotalResultCount >= 1)
{
Guid filePathFieldGuid = new Guid("{2134867A-AC67-4DAC-836C-A9264FD9D6D6}");
var affectedItem = args.Batch.Select(b => b.EntityId).Distinct().Count();
var modifiedMediaItems = args.Batch.Where(b => b.Type == ManifestOperationResultType.Modified && b.EntityType == ManifestEntityType.Media).Select(b => b.Metadata).Distinct().ToList();
var pdfItems = modifiedMediaItems.Select(b => b.FieldChanges.Where(x => x.FieldId == filePathFieldGuid && x.Value.ToLower().Contains(".pdf")).Any()).ToList();
}
}
catch (Exception ex)
{
_logger.Log("PublishEndResultProcessor is failed", EnumUtil.LoggingType.Error, EnumUtil.ExceptionTier.PublishingService, ex);
}
}
}
Custom Event :
public class CustomPublishEndHandler
{
public void OnItemPublished(object sender, EventArgs args)
{
List<string> publishedIds = new List<string>();
ILogger _logger = new Log4NetLogger();
_logger.Log("Custom Publish end event", EnumUtil.LoggingType.Info,EnumUtil.ExceptionTier.UserProfileService, null);
var itemArgs = args as ItemProcessedEventArgs;
if (itemArgs != null && !ID.IsNullOrEmpty(itemArgs?.Context?.ItemId))
{
GetPDFItemPath(itemArgs.Context.ItemId);
}
}
public void GetPDFItemPath(ID processedItem)
{
//TODO: Change this step
var item = Factory.GetDatabase("master").Items.GetItem(processedItem);
if (item != null && item.TemplateID == Sitecore.Data.ID.Parse("{0603F166-35B8-469F-8123-E8D87BEDC171}"))
{
var thread = new Thread(() => CdnFileInvalidationHelper.InvalidateContent(item.Paths.FullPath));
thread.IsBackground = true;
thread.Start();
}
}
}
Note - This custom event is working fine when adding into normal sitecore publishing event "publish:itemProcessed"
Configuration Entries:
<event name="publishingservice:publishend" patch:source="Sitecore.Publishing.Service.config">
<handler type="Sitecore.Publishing.Service.Events.PublishingJobEndHandler, Sitecore.Publishing.Service" method="StartPublishEndPipeline">
<param name="manifestResultLoadBatchSize">500</param>
</handler>
<handler type="Sitecore.Publishing.Service.Events.PublishEndHandler, Sitecore.Publishing.Service" method="TriggerPublishEnd"/>
<handler type="AllianzGI.DEXTER.Web.Extensions.Events.CustomPublishEndHandler, AllianzGI.DEXTER.Web.Extensions" method="OnItemPublished"/>
<publishEndResultBatch argsType="Sitecore.Publishing.Service.Pipelines.BulkPublishingEnd.PublishEndResultBatchArgs" patch:source="Sitecore.Publishing.Service.config">
<processor type="Sitecore.Publishing.Service.Pipelines.BulkPublishingEnd.RaiseRemoteEvents, Sitecore.Publishing.Service">
<param name="remoteEventCacheClearingThreshold">1000</param>
<param name="targetCacheClearHistory" ref="publishing.service/targetCacheClearHistory"/>
</processor>
<processor type="AllianzGI.DEXTER.Web.Extensions.Pipelines.CustomPublishEndResultBatch, AllianzGI.DEXTER.Web.Extensions"/>