public static void GetCleanerJobFiles(string jobId, ref List <string> filesHit, ref List <string> filesSkipped) { var logger = Common.GetLogger(NLog.LogLevel.Off); var batch = FilecuumCleanerConfig.GetConfig(false); filesHit = new List <string>(); filesSkipped = new List <string>(); RunCleanerJob(batch, jobId, logger, true, ref filesHit, ref filesSkipped); }
public static int TestCleanerJob(string jobId) { var logger = Common.GetLogger(); var batch = FilecuumCleanerConfig.GetConfig(false); var filesHit = new List <string>(); var filesSkipped = new List <string>(); return(RunCleanerJob(batch, jobId, logger, true, ref filesHit, ref filesSkipped)); }
public static int RunCleanerBatch(SchedulerClient schedulerClient = null) { var batchConfig = FilecuumCleanerConfig.GetConfig(false); var logger = Common.GetLogger(); // check if the job exsists if (batchConfig == null || batchConfig.FilecuumCleanerJobs == null) { logger.Info( String.Format( "No cleanerjobs found in config file. This could be an issue when the site has just restarted. Next run should go better.")); return(-1); } logger.Info(String.Format("Starting batch: {0} jobs enabled", batchConfig.FilecuumCleanerJobs.Count(job => job.Enabled == true))); int totalCnt = 0; foreach (var cleanerJob in batchConfig.FilecuumCleanerJobs) { if (schedulerClient != null) { schedulerClient.Progressing(); } int cnt = 0; // check if this job is allowed to start // is it enabled? if (!cleanerJob.Enabled) { logger.Info(String.Format("Job: {0} is currently disabled.", cleanerJob.Name)); continue; } // we're allowed to start logger.Info(String.Format("Starting job: {0}", cleanerJob.Name)); cnt = RunCleanerJob(cleanerJob.Id); logger.Info(String.Format("Finished job: {0}. files deleted {1}", cleanerJob.Name, cnt)); totalCnt += cnt; } logger.Info(String.Format("Finished batch. Files deleted: {0}.", totalCnt)); return(totalCnt); }
private static int RunCleanerJob(FilecuumCleanerConfig batchConfig, string jobId, NLog.Logger logger, bool testMode, ref List <string> filesHit, ref List <string> filesSkipped) { int retval = 0; logger.Info(String.Format("Starting job: {0}. Testmode: {1}", jobId, testMode)); logger.Debug(String.Format("Setting running job to: {0}", jobId)); // set this job as running job if (!SetRunningJob(jobId)) { logger.Error(String.Format("Fail to register job as running: {0}", jobId)); // this is killing for the job, cannot continue return(retval); } logger.Debug(String.Format("Setting last started time for: {0}", jobId)); // set the last time started if (!SetJobLastStarted(jobId)) { logger.Error(String.Format("Fail to register job starttime: {0}", jobId)); return(retval); } // find the job to perform var job = batchConfig.FilecuumCleanerJobs.FirstOrDefault(j => j.Id == jobId); if (job == null) { logger.Error(String.Format("Job not found in configuration: {0}", jobId)); return(retval); } PortalSettings ps; string mapPath = ""; switch (job.RootPath) { case Common.RootPathWebsite: ps = new PortalSettings(job.PortalId); mapPath = ps.HomeDirectoryMapPath.Substring(0, ps.HomeDirectoryMapPath.IndexOf("\\Portals")); break; case Common.RootPathHost: ps = new PortalSettings(job.PortalId); mapPath = ps.HomeDirectoryMapPath.TrimEnd('\\'); mapPath = mapPath.Substring(0, mapPath.LastIndexOf("\\")) + "\\_Default"; break; default: ps = new PortalSettings(job.RootPath); mapPath = ps.HomeDirectoryMapPath; break; } mapPath = Path.Combine(mapPath, job.Path); logger.Debug(String.Format("Job mappath set to: {0}", mapPath)); if (Directory.Exists(mapPath)) { CleanDirectory(mapPath, job, logger, testMode, ref filesHit, ref filesSkipped); } else { logger.Info(String.Format("Directory not found: {0}.", mapPath)); } // TODO: Add folder synchronisation: we need to have a portalID for that in job settings // FileSystemUtils.SynchronizeFolder(); // register job as finished SetRunningJob(Guid.Empty.ToString()); return(retval); }