Exemplo n.º 1
0
        public async Task <IActionResult> CreateSecondlyBackgroundTask([FromBody] CreateBackgroundTaskModel model,
                                                                       [FromRoute] int seconds = 0)
        {
            model.Expression = CronTemplates.Secondly(seconds);

            return(await CreateBackgroundTask(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateDailyBackgroundTask([FromBody] CreateBackgroundTaskModel model,
                                                                    [FromRoute] int atHour = 0, [FromRoute] int atMinute = 0, [FromRoute] int atSecond = 0)
        {
            model.Expression = CronTemplates.Daily(atHour, atMinute, atSecond);

            return(await CreateBackgroundTask(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateMinutelyBackgroundTask([FromBody] CreateBackgroundTaskModel model,
                                                                       [FromRoute] int minutes = 0, [FromRoute] int atSecond = 0)
        {
            model.Expression = CronTemplates.Minutely(minutes, atSecond);

            return(await CreateBackgroundTask(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateWeeklyBackgroundTask([FromBody] CreateBackgroundTaskModel model,
                                                                     [FromRoute] DayOfWeek dayOfWeek = DayOfWeek.Sunday, [FromRoute] int atHour = 0,
                                                                     [FromRoute] int atMinute        = 0, [FromRoute] int atSecond = 0)
        {
            model.Expression = CronTemplates.Weekly(dayOfWeek, atHour, atMinute, atSecond);

            return(await CreateBackgroundTask(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> CreateBackgroundTask([FromBody] CreateBackgroundTaskModel model)
        {
            if (!this.TryValidateModelOrError(model, ErrorEvents.ValidationFailed, ErrorStrings.ValidationFailed,
                                              out var error))
            {
                return(error);
            }

            if (!string.IsNullOrWhiteSpace(model.TaskType))
            {
                var type = _typeResolver.FindByFullName(model.TaskType) ??
                           _typeResolver.FindFirstByName(model.TaskType);
                if (type == null)
                {
                    return(this.BadRequestError(ErrorEvents.ResourceMissing, "No task type found with name {0}",
                                                model.TaskType));
                }

                var(success, task) = await _host.TryScheduleTaskAsync(type, model.Data, t =>
                {
                    if (model.Tags?.Length > 0)
                    {
                        t.Tags.AddRange(model.Tags);
                    }

                    if (!string.IsNullOrWhiteSpace(model.Expression))
                    {
                        t.Expression = model.Expression;
                    }
                });

                if (!success)
                {
                    return(this.NotAcceptableError(ErrorEvents.CouldNotAcceptWork,
                                                   "Task was not accepted by the server"));
                }

                return(Accepted(new Uri($"{Request.Path}/{task.Id}", UriKind.Relative)));
            }

            return(this.NotImplemented());
        }