Esempio n. 1
0
 private IEnumerable <IJobUnit> ToUnitCollection(IEnumerable <JobUnitDataObject> jobUnitDataObjects, IJobLoader loader, string jobKey)
 => jobUnitDataObjects is null
         ? new List <IJobUnit>()
         : jobUnitDataObjects.Select(u =>
 {
     IJobUnit unit   = loader.CreateUnitByType(u.Type);
     unit.Name       = u.Name;
     unit.Properties = u.Properties;
     unit.Content    = loader.GetContentByPathAsync(textFileProvider.GetAbsolutePath(u.Path, jobKey)).GetAwaiter().GetResult();
     return(unit);
 })
 .ToList();
Esempio n. 2
0
        public static IUnitExecutor GetUnitExecutor(this IJobUnit jobUnit)
        {
            if (jobUnit.Type == UnitType.DatabaseUnit)
            {
                return(new DatabaseExecutor());
            }
            else if (jobUnit.Type == UnitType.CodeUnit)
            {
                return(new CodeExecutor());
            }

            return(null);
        }
Esempio n. 3
0
        public IResult Execute(IResources resources)
        {
            if (resources is null)
            {
                throw new ArgumentNullException(nameof(resources));
            }

            // Make a copy of variables
            resources.Variables = new ConcurrentDictionary <string, string>(Variables.Where(v => v.Active)
                                                                            .Select(v => new KeyValuePair <string, string>(v.Name, v.Value)));

            foreach (var unit in Units)
            {
                // Check time remaining
                if (resources.Context.IsNearingCompletion)
                {
                    throw new ContextTimeConstraintException($"Aborting Job - {Name} - Low Context Time Remaining : {resources.Context.RemainingTime}");
                }

                var      formatter   = resources.LogFormatter.ForUnit(unit.Name, unit.UnitType);
                var      unitTimer   = new PerformanceTimer().Start();
                IJobUnit currentUnit =
                    unit is Job?resources.JobLoader.LoadJobByContent(unit.Content) : unit;

                var result      = currentUnit.Execute(resources);
                var elapsedTime = unitTimer.StopAndGetElapsedTime();
                resources.Logger.LogInformation(formatter.TextForUnit(elapsedTime.ToFormattedString(), resources.Context.RemainingTime.ToFormattedString(), result.RecordsAffected.ToString(), result.Message));
                if (!result.Success && resources.AbortOnFailure)
                {
                    return(new Result
                    {
                        Message = $"ABORTED JOB - {Name} \n {result.Message}",
                        Success = false
                    });
                }
            }
            return(new Result
            {
                Message = $"COMPLETED JOB - {Name}",
                Success = true
            });
        }