示例#1
0
        public async Task <IActionResult> CreateCronJob([FromForm] CronJobViewModel model)
        {
            var job = await _jobService.FindAsync(model.Name);

            if (job != null)
            {
                ModelState.AddModelError(nameof(model.Name), "Conflict job name");
            }

            if (!ModelState.IsValid)
            {
                return(View("CronJobCreateForm", model));
            }

            await _jobService.AddAsync(new CronJobDefinition(model.Name)
            {
                Name         = model.Name,
                Enabled      = model.Enabled,
                OS           = model.OS.ToString(),
                CPU          = model.CPU,
                Memory       = model.Memory,
                Private      = model.Private,
                Image        = model.Image,
                EnvVariables = model.EnvVariables,
                Cron         = model.Cron
            });

            _jobRegistry.Enqueue(model.Name);

            return(RedirectToAction("Definition", new { name = model.Name }));
        }
示例#2
0
        public async Task <IActionResult> UpdateCronJob([FromRoute] string name, [FromForm] CronJobViewModel model)
        {
            var job = await _jobService.FindAsync(name);

            if (job == null || job.GetJobType() != JobType.Cron)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View("CronJobUpdateForm", model));
            }

            await _jobService.UpdateAsync(new CronJobDefinition(model.Name)
            {
                Name         = model.Name,
                Enabled      = model.Enabled,
                OS           = model.OS.ToString(),
                CPU          = model.CPU,
                Memory       = model.Memory,
                Private      = model.Private,
                Image        = model.Image,
                EnvVariables = model.EnvVariables,
                Cron         = model.Cron
            });

            return(RedirectToAction("Definition", new { name = model.Name }));
        }