Friday, September 9, 2011

Advanced Publish Dialog

Every once in a while our customers ask if it’s possible to terminate a publishing job. A demand for this functionality increased as our customers started pouring more and more content into their Sitecore implementations. Sometimes an innocent  publishing job could become vicious and freeze other publications.

In this blog post I’m going to present an approach that allows a user to cancel a triggered publishing job. This became possible as new publishing pipelines were introduced in Sitecore 6.

Main idea of this tool was to add flexibility to control Publish Dialog UI through Sitecore security mechanism. For instance, hide or disable publish options and  “Publish Subitems” checkbox using user security settings. This was implemented by introducing Sitecore setting items for Publish Dialog UI controls. The items located at /sitecore/system/Settings/Publish folder.

The security settings on publish option items as well as checkbox field, Disabled, control appearance and accessibility of the controls on Publish Dialog form.
There are a few more setting items under the /Behaviors branch described below:

  • Publish Cancel Behavior
    Controls publish cancelling mechanism. If “Cancel with exception” field is checked, it throws an exception after publishing job is cancelled. This is necessary to suppress post publish events and prevent update of LastPublish property when needed.
  • Cancel Button
    Controls accessibility of “Cancel” button in Publish Dialog form. By default it has standard behavior – button is disabled after one starts publishing process. When enabled, it’s possible to cancel current publishing job.
  • Confirm subitems publish
    If enabled, it pops-up a confirmation dialog when “Publish Subitems” checkbox is selected. You can tweak the confirmation message at “/sitecore/system/Dictionary/A/Are you sure you want to publish subitems too” dictionary item in the Core database.

There are two versions of this component:

1. v1.1.1 – developed for AppPool running any .NET version

2. v1.2.0 – developed for AppPool running .NET 4.0 version ONLY. It takes advantage of a feature in .NET 4.0 that allows to speed up publishing by assigning multiple threads to publish items.

Setting that controls number of allowed threads for publishing process is located in /App_Config/Include/Sitecore.SharedSource.AdvancedPublishDialog.config file. By default allows 2 publishing threads.

<!--  Max number of concurrent threads for publishing process.
If this setting is not set Environment.ProcessorCount variable will be used.
-->
<setting name="Publishing.MaxConcurrentThreads" value="2"/>



To observe and cancel publishing jobs an additional application was added to the component – Publish Status Manager. A link to this app appears in Publish Dialog form if a user has access to the app. It’s also possible to open the app from Sitecore start button, again, if the user has access to it.


From within the app one can select a job and hit “Cancel” button to terminate it. By clicking “Cancel all”, all publishing jobs will be forced to be finished.


A few words on how publishing cancel works and its consequences.
When one triggers publishing cancellation, the job gets set to Finished state which is utilized in customized ProcessQueue processor of <publish> pipeline to get off the publishing loop. If “Publish Cancel Behavior” is enabled (setting described above), then custom ProcessPublishCancel pipleline will throw an exception to suppress post publish events.


The caveats of cancelling publishing process.


Publishing of each item is an atomic operation. When you cancel the publishing, there is no mechanism to roll back changes for already processed items. The data for already published items will make their way to the publishing target database. The search indexes will index new data as soon as IndexingManager reads new entries from History table. New published data may not appear on the public site if old data sit in HTML cache of presentation controls and “publish:end” event did not rise to clear it out.


The “Cancel with exception” behavior on “Publish Cancel Behavior” setting item can suppress “publish:end” event and leave LastPublish property unchanged. This could be required if one wants to re-publish processed items, which got published before the publishing job was cancelled, at next Incremental publishing.
If this setting is not set, then caches will be cleared for all processed items whenever publishing is terminated. The LastPublish property will be updated with publish cancellation time. Next Incremental publish will pick up items from the point where they were left when publish cancel event got fired.


Having said this, I’d recommend to leave “Cancel with exception” field unchecked unless you have a strong requirement to republish processed items along with those that were skipped by publish cancellation event.


Here as screencast of quick overview of the component:


Advanced Publish Dialog for Sitecore

UPDATED on Sep 20, 2011
Support for v1.1.x was dropped as v1.2.x does not require AppPool to run .NET 4.0. The link to v1.1.x is no longer available.


Below are the links to the mentioned Sitecore packages:
Sitecore package of AdvancedPublishDialog.


If you have any enhancement ideas or additional features for this module, feel free to express them in the comments.
Enjoy!

9 comments:

Matt Hovany said...

nice work ivan

Ivan said...

Thanks Matt!

shejoy said...
This comment has been removed by the author.
shejoy said...

Hey... How can i get a maximize button into it?

Ivan said...

I assume you want to add maximize button to Publish Status Manager app. To do so, go to /Applications/Publish Status Manager item in core database and un-check "Disable maximize" checkbox field.

David said...

Hi Ivan,

Great job!
What else would be great is if you could choose a start item within the publish dialog.

Regards,
David

Whit said...

Ivan,

This is a great module. I did have a question though. Can only admins see the "Publish Status Manager" in the Sitecore menu of the Desktop? If not, what permissions do I need to give a user for them to see this menu option?

Ivan said...

Hi Whit,
Yes, it's possible to modify access to this app.
If you switch database context to Core database, you can find "Publish Status Manager" under the /sitecore/content/Applications branch. Use Security Editor and Access Viewer to customize access to the app.

Richard Cabral said...

Hi Ivan,

Looks pretty good, but I see publish jobs get stuck, and they don't cancel when asked. Any ideas?