0

I am using Publishing Service and tried to implement the Publish Manager API to retrieve Publish Status, but once the publishing is completed (successfully or unsuccessfully) the PublishManager.GetStatus(handle) returns null.

So, I am not able to actually get the exact status of publishing once its completed.

Below is the code that I tried to implement:

var handle = PublishManager.PublishItem(item, new[] { _webDb }, _webDb.Languages, true, false);

if (handle != null)
{
  var publishStatus = PublishManager.GetStatus(handle);
  if (publishStatus != null)
  {
    while (!publishStatus.IsDone)
    {
      Thread.Sleep(30000);
      publishStatus = PublishManager.GetStatus(handle);
    }

     // Log the publishing status once its finished
     Logger.Info("Publish Status: " + publishStatus.State);
     Logger.Info("Publish Status : IsDone: " + publishStatus.IsDone);
     Logger.Info("Publish Status : IsExpired: " + publishStatus.Expired);
     Logger.Info("Publish Status : IsFailed: " + publishStatus.Failed);                            
    }
}

Also I tried to implement below, but this also returns Publish Status as null

var handle = PublishManager.PublishItem(sitemapRoot, new[] { _webDb }, _webDb.Languages, true, false);
PublishManager.WaitFor(handle);

var publishStatus = PublishManager.GetStatus(handle);

Could there be any other way by which we can get the Publishing Status to know whether it was a success or failure?

1
  • You can take a look at at the various APIs from the publishing dialog to figure out how to report the various publishing status and results. – Vincent Lui Apr 15 at 10:06
0

If you are using the Publishing Service you can use the values that are shown on the Dashboard by accessing /sitecore/client/Applications/Publishing/Dashboard:

enter image description here

If you look at the Network tab you will see that it is doing a call to the API /sitecore/api/ssc/publishing/jobs/%7B00000000-0000-0000-0000-000000000000%7D/All?sourceDatabase=master. This basically retrieves a JSON with all the Jobs aswell as their statuses. The first part of the JSON looks like this:

{
  "Messages": [],
  "Active": [],
  "Queued": [],
  "Recent": [
    {
      "ManifestIdList": [
        "39cbd98d-7abd-4c35-b152-6c18d7a81532"
      ],
      "Type": {
        "DisplayName": "Single Item"
      },
      "TypeDisplayName": "Item publish",
      "ItemId": "{6bfa19da-4596-473d-8c78-0411cfd83799}",
      "SourceDatabase": "master",
      "ItemName": "CommonName6bfa19da-4596-473d-8c78-0411cfd83799",
      "RequestedBy": "sitecore\\admin",
      "Status": "Completed",
      "StatusMessage": "OK",
      "Languages": [
        {
          "Code": "en",
          "DisplayName": "English"
        }
      ],

You would use the "Status": "Completed" in your code to verify if the Job finished successfully. The same would apply to see if the Job is in Active, Queued or Recent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.