public async Task CreateTaskDefinition(TaskDefinitionModel model, int accId)
        {
            var id = IdGeneratorHelper.GenerateId("td", accId.ToString());
            await _taskDefinitionRepository.CreateTaskDefinition(new TaskDefinition()
            {
                Name = model.Name,
                Id   = id,
                ContainerImageName = model.ContainerImageName,
                GroupId            = model.GroupId,
                MaxVcpu            = model.MaxVcpu,
                MinVcpu            = model.MinVcpu,
                TaskType           = (int)model.TaskType
            });

            if (model.TaskType == TaskDefinitionType.QuartzCron)
            {
                await _taskDefinitionRepository.CreateTaskDefinitionQuartzCron(new TaskDefinitionQuartzCron()
                {
                    Id = IdGeneratorHelper.GenerateId("td-qc", accId.ToString()),
                    QuartzExpression = model.QuartzCron.QuartzExpression,
                    TaskDefinitionId = id
                });
            }
            else if (model.TaskType == TaskDefinitionType.ReplicatedServer)
            {
                await _taskDefinitionRepository.CreateTaskDefinitionReplicaServer(new TaskDefinitionReplicatedServer()
                {
                    Id               = IdGeneratorHelper.GenerateId("td-qc", accId.ToString()),
                    MaximumCount     = model.ReplicaServer.MaximumCount,
                    MinimumCount     = model.ReplicaServer.MinimumCount,
                    TaskDefinitionId = id
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <Guid> CreateTask(TaskDefinitionModel textTaskModel)
        {
            var textTask = _mapper.Map <TextTask>(textTaskModel);

            textTask.Id = new Guid();
            await _taskDbContext.TextTask.AddAsync(textTask);

            //await _taskDbContext.SaveChangesAsync();
            var searchWorld = new List <SearchWords>();

            foreach (var str in textTaskModel.SearchWords)
            {
                searchWorld.Add(new SearchWords()
                {
                    Id = new Guid(), IdTask = textTask.Id, Word = str
                });
            }
            await _taskDbContext.SearchWords.AddRangeAsync(searchWorld);

            await _taskDbContext.SaveChangesAsync();

            //Добавление в локальный кэш - задачу, на родсчет совпадений
            _cacheTaskService.cashTaskAdd(new CashTask()
            {
                Id               = textTask.Id,
                StartTime        = textTask.StartTime.ToUniversalTime(),
                EndTime          = textTask.EndTime.ToUniversalTime(),
                CountOfRepeating = textTask.CountOfRepeating,
                SearchWords      = textTaskModel.SearchWords,
                State            = TaskFlags.New
            });

            return(textTask.Id);
        }
        public async Task CreateTask_ShouldExecuteRepository_CreateTask()
        {
            //TODO необходимо тестирование на создание задачи (с неоходимым интервалом времени).
            // Проверки отработки тасков (записи в SQL) по правильности отработки (по времени, по непосредственному результату)
            // Создание нового текста в TextDB и проверки отработки его
            // Проверки неотработки задачи, когда время задачи вышло. (также создать новый Text? или проверки задач в кеше)

            using (var context = new TaskDbContext(contextOptions, configuration, DataBaseFlags.Test))
            {
                //Arrange
                var taskDefinitionModel = new TaskDefinitionModel()
                {
                    StartTime        = DateTime.Now.AddHours(-4),
                    EndTime          = DateTime.Now.AddHours(4),
                    CountOfRepeating = 60,
                    SearchWords      = new List <string>()
                    {
                        "ab", "аб", "_"
                    }
                };

                var textService = new Services.TaskService(context, _mapper, _cacheTaskService.Object);
                var controller  = new TaskController(textService);

                //Act
                var actionResultFromController = await controller.CreateTask(taskDefinitionModel);

                //var guid = (Guid)actionResultFromController.Value;

                //Assert
                //Assert.NotNull(actionResultFromController.Value);
                Assert.True(actionResultFromController.Value != Guid.Empty);
            }
        }
Ejemplo n.º 4
0
 public async Task <ActionResult <Guid> > CreateTask(TaskDefinitionModel TaskDefinitionModel)
 {
     return(await _taskService.CreateTask(TaskDefinitionModel));
 }
 public async Task <IActionResult> CreateTaskDefinition([FromBody] TaskDefinitionModel model)
 {
     await _taskDefinitionGroupService
 }