private PeriodicServiceEntity AddService(string key, PeriodicServiceOptions options, long iteration)
        {
            var result = new PeriodicServiceEntity
            {
                Name        = key,
                Added       = DateTime.UtcNow,
                ServiceType = options.ServiceType
            };

            result = UpdateService(key, result, options, iteration);
            return(result);
        }
        public void UpdateRun(PeriodicServiceOptions options, long iteration, long runDuration, string error)
        {
            if (options == null)
            {
                throw new ArgumentException(nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.ServiceName))
            {
                throw new Exception("options.ServiceName is empty");
            }

            ServicesDictionary.AddOrUpdate(options.ServiceName, s => AddService(s, options, iteration), (s, entity) => UpdateRunService(s, entity, options, iteration, runDuration, error));
        }
        private PeriodicServiceEntity UpdateRunService(string key, PeriodicServiceEntity e, PeriodicServiceOptions options, long iteration, long runDuration, string error)
        {
            var result = UpdateService(key, e, options, iteration);

            result.LastRun = DateTime.UtcNow;
            result.LastRunDurationMilliseconds = runDuration;
            result.LastRunError = error;
            return(result);
        }
 private PeriodicServiceEntity UpdateService(string key, PeriodicServiceEntity e, PeriodicServiceOptions options, long iteration)
 {
     e.Enabled            = options.Enabled;
     e.Updated            = DateTime.UtcNow;
     e.Iteration          = iteration;
     e.PeriodMilliseconds = options.PeriodMilliseconds;
     e.Options            = Serialize(options);
     return(e);
 }