Skip to main content

Command Palette

Search for a command to run...

Scheduled Publishing in Sitecore AI

Published
2 min read

Introduction

Scheduled publishing is one of the commonly requested feature by the content authors. In this blog we use a unique combination to achieve this functionality.

  • Use Sitecore authoring and Management Api to perform publishing.

  • Use Hangfire for scheduling.

Flow Diagram

1) Content Authors/developers can use the Landing page to schedule the publish by specifying publish date, item path, type of publish, include sub items, include related items, publishing Mode and display name of the publish

2) Hangfires stores the above details in the database and schedules the job

3) At the time of schedule hangfire makes the graphql api and creates a publish job in Sitecore

4) Sitecore responds with the operation id which hangfire uses to check the status and retries the job if there is a failure, sends notification to the user if the job is successful

Hangfire Dashboard

Technical Details

Hangfire packages to be used

  • Hangfire.AspNetCore

  • Hangfire.SqlServer

Token Endpoint

Graphql Endpoint

Publishing Mutation

mutation {
  publishItem(input: {
    displayName: ""
    languages: [""]
    publishItemMode: 
    publishRelatedItems: 
    publishSubItems: 
    rootItemId: ""
    sourceDatabase: ""
    targetDatabases: [""]
  })
 {
    operationId
  }
}

Github Repository

Complete implementation can be found here

Notes

  • Hangfire is used as an example, we can utilize any language/packages that supports scheduling (eg next js cron jobs)

  • The application can be extended to add environments and schedule in the required environments

  • Currently this is a completely Isolated Application, however the same logic can be extended to create a marketplace application integrated within the sitecore environment

Conclusion

Sitecore Authoring API is very powerful and can be used to automate tasks in Sitecore. In today's tech-driven era, we can create a custom agent to perform complex operations by leveraging the Authoring API.

M

Great blog with Github, keep rocking!