Exemplo n.º 1
0
        public static bool IsTriggered(this DeploymentConfig schedule, ExecutionSchedule scheduleOld)
        {
            if (schedule?.enable != true)
            {
                return(false);
            }

            if (schedule.max > 0 && schedule.max <= scheduleOld.executions)
            {
                return(false);
            }

            if (schedule.schedules.IsNullOrEmpty())
            {
                return(false);
            }

            if (schedule.cron?.ToCron()?.Compare(DateTime.UtcNow) == 0)
            {
                return(true);
            }

            if (schedule.trigger > 0 && scheduleOld.trigger < schedule.trigger)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public static void UpdateExecutionSchedule(this ExecutionSchedule schedule, DirectoryInfo rootStatus)
        {
            var statusFile = schedule.GetStatusFileInfo(rootStatus);

            if (!statusFile.Directory.Exists)
            {
                statusFile.Directory.Create();
            }

            statusFile.WriteAllText(schedule.JsonSerialize());
        }
Exemplo n.º 3
0
        public static ExecutionSchedule LoadExecutionSchedule(this ExecutionSchedule schedule, DirectoryInfo rootStatus)
        {
            if (schedule.id.IsNullOrEmpty())
            {
                throw new Exception("Schedule ID was not defined, could not load.");
            }

            var statusFile = schedule.GetStatusFileInfo(rootStatus);

            if (!statusFile.Directory.Exists)
            {
                statusFile.Directory.Create();
            }

            if (!statusFile.Exists)
            {
                statusFile.WriteAllText("{ }");
            }

            return(statusFile.DeserialiseJson <ExecutionSchedule>());
        }
Exemplo n.º 4
0
        public static bool IsTriggered(this ExecutionSchedule schedule, ExecutionSchedule scheduleOld, bool masterTrigger)
        {
            if (schedule?.enable != true)
            {
                Console.WriteLine($"Schedule '{schedule.id}' was not enabled.");
                return(false);
            }

            if (schedule.max > 0 && schedule.max <= scheduleOld.executions)
            {
                Console.WriteLine($"Schedule '{schedule.id}' was executed maximum number of {schedule.max} times.");
                return(false);
            }

            if (schedule.commands.IsNullOrEmpty())
            {
                Console.WriteLine($"Schedule '{schedule.id}' commands were not defined.");
                return(false);
            }

            if (schedule.enableMasterTrigger && masterTrigger)
            {
                return(true);
            }

            if (schedule.cron?.ToCron()?.Compare(DateTime.UtcNow) == 0)
            {
                return(true);
            }

            if (schedule.trigger > 0 && scheduleOld.trigger < schedule.trigger)
            {
                return(true);
            }

            //Console.WriteLine($"Schedule '{schedule.id}' trigger: '{schedule.trigger}/{scheduleOld.trigger}', cron: '{schedule.cron ?? "undefined"}' was NOT actived.");
            return(false);
        }
Exemplo n.º 5
0
 public static string GetFileSafeId(this ExecutionSchedule s)
 => s?.id?.ToAlphaNumeric(whitelist: new char[] { '-', '_' });
Exemplo n.º 6
0
 public static FileInfo GetStatusFileInfo(this ExecutionSchedule s, DirectoryInfo rootDirectory)
 => PathEx.RuntimeCombine(rootDirectory.FullName, $"{(s.GetFileSafeId() ?? "tmp")}.json").ToFileInfo();
Exemplo n.º 7
0
 public static FileInfo GetLogFileInfo(this ExecutionSchedule s, DirectoryInfo logDirectory)
 => PathEx.RuntimeCombine(logDirectory.FullName, $"{(s.GetFileSafeId() ?? "tmp")}.log").ToFileInfo();