Auto sync specific pages using scheduled tasks

Lokesh Uppalapati asked on June 27, 2018 14:18

Hi All,

I have a requirement to Auto sync a specific page using scheduled task in kentico10

I have configured staging credentials and used following custom code for scheduled task.But the pages are not syncing when i run the scheduled tasks

here is my code

using CMS.DataEngine;

using CMS.DocumentEngine;

using CMS.Membership;

using CMS.SiteProvider;

using CMS.Synchronization;

using CMS;

using CMS.Scheduler;

using System;

using System.Data;

using CMS.EventLog;

using System.Collections.Generic;

using System.Linq;

[assembly: RegisterCustomClass("News.PatroPH", typeof(News.PatroPH))]

namespace News

{

public class PatroPH : ITask

{

    public string Execute(TaskInfo ti)

    {

        try

        {

            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);


            // Gets the page (tree node) for synchronization
            TreeNode node = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/DZMM", "en-us", false, null,false,false,true);

            if (node != null)
            {
                // Gets the target server
                //ServerInfo si = ServerInfoProvider.GetServerInfo("Staging.Target1", SiteContext.CurrentSiteID);
                ServerInfo si = ServerInfoProvider.GetServerInfo("DZMMTargetServerName", SiteContext.CurrentSiteID);

                if (si != null)
                {
                    // Logs the synchronization tasks
                    List<ISynchronizationTask> tasks = DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, true, false, tree, si.ServerID, null, false);

                    // Gets the IDs of the tasks and runs the synchronization
                    new StagingTaskRunner(si.ServerID).RunSynchronization(tasks.Select(t => t.TaskID));

                }
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        return "success";
    }
}

}

Correct Answer

Lokesh Uppalapati answered on June 28, 2018 14:01

Hello Guys,

Thanks everyone for your suggestions

ServerInfo si = ServerInfoProvider.GetServerInfo("DZMMTargetServerName", SiteContext.CurrentSiteID);

In the above line i thought it is getting server name from textbox so i have given my server textbox name

now i have changed it and given my staging server name as below and it is working fine.

ServerInfo si = ServerInfoProvider.GetServerInfo("Your staging server name", SiteContext.CurrentSiteID);

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on June 27, 2018 21:51

Do you see anything at the event log regarding your tasks?

0 votesVote for this answer Mark as a Correct answer

Lokesh Uppalapati answered on June 28, 2018 07:02

Hello Peter,

I can't see anything in event log regarding tasks.

Is there anything else I can check

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on June 28, 2018 07:21

When you run the code in the debug in Visual studio - is the task code executed correctly, are the correct tasks loaded, and so on?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.