Exemplo n.º 1
0
        public async Task <bool> Run(StaffingScheduleQueueItem item)
        {
            var logic = new StaffingScheduleLogic();
            await logic.Process(item);

            return(true);
        }
Exemplo n.º 2
0
        public async Task ProcessAsync(Commands.StaffingScheduleCommand command, IQuidjiboProgress progress, CancellationToken cancellationToken)
        {
            progress.Report(1, $"Starting the {Name} Task");

            await Task.Factory.StartNew(() =>
            {
                var _departmentsService    = Bootstrapper.GetKernel().Resolve <IDepartmentsService>();
                var _scheduledTasksService = Bootstrapper.GetKernel().Resolve <IScheduledTasksService>();
                var logic = new StaffingScheduleLogic();

                var allItems = _scheduledTasksService.GetAllUpcomingStaffingScheduledTaks();

                if (allItems != null && allItems.Any())
                {
                    // Filter only the past items and ones that are 5 minutes 30 seconds in the future
                    var items = (from st in allItems
                                 let department = _departmentsService.GetDepartmentByUserId(st.UserId)
                                                  let runTime = st.WhenShouldJobBeRun(TimeConverterHelper.TimeConverter(DateTime.UtcNow, department))
                                                                where
                                                                runTime.HasValue && runTime.Value >= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department) &&
                                                                runTime.Value <= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department).AddMinutes(5).AddSeconds(30)
                                                                select new
                    {
                        ScheduledTask = st,
                        Department = department
                    }).ToList();

                    if (items != null && items.Any())
                    {
                        _logger.LogInformation("StaffingSchedule::Staffing Levels to Change: " + items.Count());

                        foreach (var i in items)
                        {
                            var qi           = new StaffingScheduleQueueItem();
                            qi.ScheduledTask = i.ScheduledTask;
                            qi.Department    = i.Department;

                            _logger.LogInformation("StaffingSchedule::Processing Staffing Schedule:" + qi.ScheduledTask.ScheduledTaskId);

                            var result = logic.Process(qi);

                            if (result.Item1)
                            {
                                _logger.LogInformation($"StaffingSchedule::Processed Staffing Schedule {qi.ScheduledTask.ScheduledTaskId} successfully.");
                            }
                            else
                            {
                                _logger.LogInformation($"StaffingSchedule::Failed to Process staffing schedule {qi.ScheduledTask.ScheduledTaskId} error {result.Item2}");
                            }
                        }
                    }
                }
            }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);



            progress.Report(100, $"Finishing the {Name} Task");
        }
Exemplo n.º 3
0
        public void Run(StaffingScheduleQueueItem item)
        {
            var logic = new StaffingScheduleLogic();

            logic.Process(item);
        }
Exemplo n.º 4
0
        public async Task ProcessAsync(Commands.StatusScheduleCommand command, IQuidjiboProgress progress, CancellationToken cancellationToken)
        {
            try
            {
                progress.Report(1, $"Starting the {Name} Task");

                //await Task.Run(async () =>
                //{
                var _departmentsService    = Bootstrapper.GetKernel().Resolve <IDepartmentsService>();
                var _scheduledTasksService = Bootstrapper.GetKernel().Resolve <IScheduledTasksService>();
                var logic = new StaffingScheduleLogic();

                var allDepartments = await _departmentsService.GetAllAsync();

                var allItems = await _scheduledTasksService.GetAllUpcomingStatusScheduledTasksAsync();

                if (allItems != null && allItems.Any())
                {
                    // Filter only the past items and ones that are 5 minutes 30 seconds in the future
                    var items = (from st in allItems
                                 let department = allDepartments.FirstOrDefault(x => x.DepartmentId == st.DepartmentId)
                                                  let runTime = st.WhenShouldJobBeRun(TimeConverterHelper.TimeConverter(DateTime.UtcNow, department))
                                                                where
                                                                runTime.HasValue && runTime.Value >= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department) &&
                                                                runTime.Value <= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department).AddMinutes(5).AddSeconds(30)
                                                                select new
                    {
                        ScheduledTask = st,
                        Department = department
                    }).ToList();

                    if (items != null && items.Any())
                    {
                        _logger.LogInformation("StatusSchedule::Status Levels to Change: " + items.Count());

                        foreach (var i in items)
                        {
                            var qi = new StaffingScheduleQueueItem();
                            qi.ScheduledTask = i.ScheduledTask;
                            qi.Department    = i.Department;

                            _logger.LogInformation("StatusSchedule::Processing Status Schedule:" + qi.ScheduledTask.ScheduledTaskId);

                            var result = await logic.Process(qi);

                            if (result.Item1)
                            {
                                _logger.LogInformation($"StatusSchedule::Processed Status Schedule {qi.ScheduledTask.ScheduledTaskId} successfully.");
                            }
                            else
                            {
                                _logger.LogInformation($"StatusSchedule::Failed to Process status schedule {qi.ScheduledTask.ScheduledTaskId} error {result.Item2}");
                            }
                        }
                    }
                }
                //}, cancellationToken);

                progress.Report(100, $"Finishing the {Name} Task");
            }
            catch (Exception ex)
            {
                Resgrid.Framework.Logging.LogException(ex);
                _logger.LogError(ex.ToString());
            }
        }