Delete inactive contacts scheduled task

Faye Spath asked on November 28, 2022 20:54

I need to know how to get the delete inactive contacts to be scheduled daily at 2:00 AM This post some people say you can do it by the scheduled task others say you have to create a custom scheduled task. https://devnet.kentico.com/questions/custom-contacts-deletion-scheduled-task-only-runs-once Mine didnt even run once? I can see limitting the 2:00 AM but should have some documentation some where stating this also if we have to manually run it it would help having this in the documentation because the way it is set up it looks like we can modify the values of the scheduled task and get it to run.

Faye

Recent Answers


Brenden Kehren answered on November 29, 2022 00:40

Can you specify what version and development model you're using?

The scheduled task is hard coded to run at 2am (server time) and only delete 1000 contacts at a time. If you're using v13 MVC you should be able to use something like this to override and create your own service.
(Code reference from Chris Bass)

using CMS;
using CMS.ContactManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Site;
​
​
​
[assembly: RegisterImplementation(typeof(IOffPeakService), typeof(AlwaysOffPeakService), Priority = CMS.Core.RegistrationPriority.Default)]
namespace Site
{
    /// <summary>
    /// Summary description for AlwaysOffPeakService
    /// </summary>
    public class AlwaysOffPeakService : IOffPeakService
    {
        public AlwaysOffPeakService()
        {
        }
​
        public DateTime GetNextOffPeakPeriodStart(DateTime dateTime)
        {
            return DateTime.Now;
        }
​
        public bool IsOffPeak(DateTime dateTime)
        {
            return true;
        }
    }
}
1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on November 29, 2022 08:46

The only other thing to keep in mind with "Delete inactive contacts" task is that it is rescheduling itself automatically at the end of execution. If this task fails with some exception (it could be a timeout on SQL or something) the Delete task will not run next time.

And it's hard to notice this straight away. We had issues in the past where the admin only noticed that delete contacts task wasn't running for a few months which led to gradual regression of website performance. Therefore to make it more robust we've written our own custom task which just executes the same stored procedure as Kentico default one - Proc_OM_Contact_MassDelete

0 votesVote for this answer Mark as a Correct answer

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