Exemple #1
0
        public void CalculateOutputFormYearJob_Success()
        {
            var date = new DateTime(2019, 2, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();

            var yearHandler = CalculateModifiedYearJobHandlerTest.Build(dbContext, jobRepo);
            var yearJob     = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(yearJob);

            Task task = yearHandler.ExecuteAsync(yearJob);

            task.Wait();

            var weekHandler = Build(dbContext, jobRepo);
            var weekJob     = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(weekJob);

            task = weekHandler.ExecuteAsync(weekJob);
            task.Wait();

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(true, week.Success);
        }
        public void HostingService_MySql()
        {
            var date = new DateTime(2019, 2, 1);

            var optionsBuilder = new DbContextOptionsBuilder <TypiconDBContext>();

            optionsBuilder.UseMySql("server=localhost;UserId=root;Password=z2LDCiiEQFDBlkl3eZyb;database=typicondb;",
                                    //optionsBuilder.UseMySql("server=31.31.196.160;UserId=u0351_mysqluser;Password=gl7fdQ45GZyqydXrr2BZ;database=u0351320_typicondb;",
                                    mySqlOptions =>
            {
                mySqlOptions.ServerVersion(new Version(8, 0, 15), ServerType.MySql);
            });
            optionsBuilder.EnableSensitiveDataLogging();

            var dbContext = new TypiconDBContext(optionsBuilder.Options);

            var jobRepo = new JobRepository();

            //var yearHandler = CalculateModifiedYearJobHandlerTest.Build(dbContext, jobRepo);
            var yearJob = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(yearJob);

            //Task task = yearHandler.ExecuteAsync(yearJob);
            //task.Wait();

            //var weekHandler = CalculateOutputFormWeekJobTest.Build(dbContext, jobRepo);
            var weekJob = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(weekJob);

            //task = weekHandler.ExecuteAsync(weekJob);
            //task.Wait();

            var service = new JobAsyncHostedService(jobRepo, CommandProcessorFactory.CreateJobProcessor(dbContext, jobRepo));

            var token = new CancellationTokenSource();

            Task.Factory.StartNew(() => service.StartAsync(token.Token));

            while (jobRepo.Create(weekJob).Failure)
            {
                Thread.Sleep(50);
            }

            token.Cancel();

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(true, week.Success);
        }
        public void JobRepository_MoreThan()
        {
            var queue = new JobRepository();

            queue.Create(new CalculateModifiedYearJob(1, 2019));
            queue.Create(new CalculateModifiedYearJob(1, 2020));
            queue.Create(new CalculateModifiedYearJob(1, 2021));
            queue.Create(new CalculateModifiedYearJob(1, 2021));

            var c = queue.Reserve(6);

            Assert.AreEqual(3, c.Count());
        }
Exemple #4
0
        public void CalculateOutputFormYearJob_Failed()
        {
            var date = new DateTime(2019, 9, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();
            var handler   = Build(dbContext, jobRepo);

            var job = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(job);

            var task = handler.ExecuteAsync(job);

            task.Wait();

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(false, week.Success);
        }
Exemple #5
0
        async public Task <IActionResult> AddJob([FromBody] AddJob job, int cpId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (job == null)
            {
                return(BadRequest(new
                {
                    success = false,
                    error = "Body can not be null"
                }));
            }

            try
            {
                Job createdJob = await jobRepository.Create(job.job);

                if (createdJob == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                DanhSachDN_Job temp = new DanhSachDN_Job {
                    ma_cong_viec = createdJob.ma_cong_viec, ma_doanh_nghiep = cpId, ngay_dang = DateTime.Now, trang_thai = false
                };

                DanhSachDN_Job createdDN_Job = await danhSachDNJobRepository.Create(temp);

                if (createdDN_Job == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }


                bool createdJobSkills = await jobService.CapNhatJobSkill(job.skills, createdJob.ma_cong_viec);

                if (createdJobSkills == false)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                queue.Enqueue(job);

                return(Ok(new
                {
                    success = true,
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task HostingService_OutputForm()
        {
            var date = new DateTime(2019, 2, 1);

            var dbContext = TypiconDbContextFactory.Create();
            var jobRepo   = new JobRepository();

            var yearHandler = CalculateModifiedYearJobHandlerTest.Build(dbContext, jobRepo);
            var yearJob     = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(yearJob);

            Task task = yearHandler.ExecuteAsync(yearJob);

            task.Wait();

            var weekHandler = CalculateOutputFormWeekJobTest.Build(dbContext, jobRepo);
            var weekJob     = new CalculateOutputFormWeekJob(1, 1, date);

            jobRepo.Create(weekJob);

            task = weekHandler.ExecuteAsync(weekJob);
            task.Wait();

            var service = new JobAsyncHostedService(jobRepo, CommandProcessorFactory.Create(dbContext));

            await service.StartAsync(CancellationToken.None);

            while (jobRepo.GetAll().Count() > 0)
            {
                Thread.Sleep(50);
            }

            var queryProcessor = QueryProcessorFactory.Create();

            var week = queryProcessor.Process(new OutputWeekQuery(1, date, new OutputFilter()
            {
                Language = "cs-ru"
            }));

            Assert.AreEqual(true, week.Success);
        }
        public void CalculateModifiedYearJob_Test()
        {
            var dbContext  = TypiconDbContextFactory.Create();
            var jobRepo    = new JobRepository();
            var jobHandler = Build(dbContext, jobRepo);

            var job = new CalculateModifiedYearJob(1, 2019);

            jobRepo.Create(job);

            var task = jobHandler.ExecuteAsync(job);

            task.Wait();

            Assert.AreEqual(0, jobRepo.GetAll().Count());
        }
        public void ReloadRulesJob_Test(bool isTrue, TypiconVersionStatus status)
        {
            var context = TypiconDbContextFactory.Create();

            var jobRepo = new JobRepository();

            var handler = new ReloadRulesJobHandler(GetConfigRepo(), context, jobRepo);

            var job = new ReloadRulesJob(1, status);

            jobRepo.Create(job);

            var task = handler.ExecuteAsync(job);

            task.Wait();

            Assert.AreEqual(0, jobRepo.GetAll().Count());
        }
Exemple #9
0
        public async Task <IActionResult> Create([FromBody] Job job)
        {
            if (String.IsNullOrEmpty(job.Name))
            {
                return(Ok(new
                {
                    status = ResultStatus.STATUS_INVALID_INPUT,
                    message = "Tên nghề nghiệp không được để trống"
                }));
            }
            await jobRepository.Create(job);

            return(Ok(new
            {
                status = ResultStatus.STATUS_OK,
                data = job
            }));
        }
Exemple #10
0
 internal Job Create(Job newJob)
 {
     newJob.Id = _repo.Create(newJob);
     return(newJob);
 }
Exemple #11
0
 //CREATE/POST
 internal Job Create(Job newJob)
 {
     return(_repo.Create(newJob));
 }
Exemple #12
0
        public RestResult Post(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var job = _repository.GetById(int.Parse(id));

            if (job == null)
            {
                return(Rest(null));
            }

            var jobInstance = job.InstanceId != Guid.Empty ? _repository.Get(job.InstanceId) : _repository.Create(job);

            _executor.StartAsync(jobInstance, new JobExecutionOptions {
                Trigger = ScheduledJobTrigger.User
            });

            return(Rest(null));
        }
Exemple #13
0
 public Job Create(Job newJob)
 {
     newJob.Id = _repo.Create(newJob);
     return(newJob);
 }
 internal Job Create(Job job)
 {
     return(_repo.Create(job));
 }