9
votes

As far as I can tell, out-of-box Sitecore doesn't come with a way to publish something at a specific time. By that I mean an EXACT time of day.

As I understand it, you turn on the publishing agent by setting an interval...let's say every half hour (doesn't seem like it would be a good idea to auto-publish more often than that). Then you have your authors set publishing restrictions on items. When that restriction passes, the item is published the next time the publishing agent runs. Correct?

The above scenario doesn't allow for something being published at a specific time of day. If I have a page that needs to go live at 8am tomorrow, it's possible that it wouldn't be live until around 8:30am depending on when the interval is run in relationship to 8am. Do I have that correct?

What is the best approach to set things up so that authors can publish items at specific times of day?

4

4 Answers

5
votes

You are correct on the publishing agent. All of Sitecore's agents are interval based, and are not guaranteed to run at a specific time. You can crank the interval way down, but since publishing is a serial task for the most part, If your interval is, say, 5 minutes, and your site publish takes 7 minutes, you'll get a pileup of publish jobs (as one is put on the queue every 5min).

The only way to guaranty a publish occurs at a specific time is to have someone do it at that time via the content editor. Automation-wise, Sitecore doesn't have anything for this. In the past, where clock time was crucial for a job to run, I've seen Windows scheduled tasks run and hit a URL on the site to kick it off.

The other approach you could take for content if time of day is that critical, is to have a datetime field on a base template, then have a httpBeginRequest pipeline step that runs after the ItemResolver. Have that step read the time on the field, then about the pipeline if the item isn't "live" yet.

2
votes

There is a module in the Sitecore Marketplace for this:

https://marketplace.sitecore.net/en/Modules/Automated_Publisher.aspx

Everytime an author sets publishing restrictions to an item, the module adds a new scheduled task and publishs the item at the specific time.

2
votes

You can follow the instructions in this link to trigger a task on a specific time, You will have to write the code for the publishing task, Something like :

PublishOptions options = 
       new PublishOptions(master, web, PublishMode.Smart, 
       Sitecore.Globalization.Language.Parse("en"), DateTime.Now) 
            {
                Deep = true;
            };

Publisher publisher = new Publisher(options);
publisher.PublishAsync();
0
votes

I had to do this task also. You can't use the standard sitecore schedulers because they only run x periods and this may vary depending on when the Apppool of site core was recycled,etc. I ended up jumping though the following hoops:

Build a class in your web site:

public  class PublishCommand
{
    public void RunFullPublish()
    {
        using (new SecurityDisabler())
        {
            var source = Factory.GetDatabase("master");
            var target = Factory.GetDatabase("web");

            List<PublishOptions> options = new List<PublishOptions>();
            foreach (Language language in source.Languages)
            {
                options.Add(new PublishOptions(source, target, PublishMode.Full, language, DateTime.Now));
            }

            PublishManager.Publish(options.ToArray());
        }
    }
}

this then needs exposing on your web site somehow. I built a web page that I could call. You then need a mechanism to call the web page. I wrote a powershell script (RunUrl.ps1):

param([string]$url="https:/mywebsite/RunFullPublish.aspx")

Write-Host "calling URL $url"
$request = [System.Net.WebRequest]::Create($url)
$response = $request.GetResponse()
$response.Close()

Powershell based on this answer

I can then call the powershell script every x period of time using a standard windows scheduler.