Exemplo n.º 1
0
        private Task CreateTask(string name, string flux, string every, string cron, string orgId)
        {
            Arguments.CheckNonEmptyString(name, nameof(name));
            Arguments.CheckNonEmptyString(flux, nameof(flux));
            Arguments.CheckNonEmptyString(orgId, nameof(orgId));

            if (every != null)
            {
                Arguments.CheckDuration(every, nameof(every));
            }

            var task = new Task(orgID: orgId, name: name, status: TaskStatusType.Active, flux: flux);

            var repetition = "";

            if (every != null)
            {
                repetition += "every: ";
                repetition += every;
            }

            if (cron != null)
            {
                repetition += "cron: ";
                repetition += "\"" + cron + "\"";
            }

            task.Flux = $"option task = {{name: \"{name}\", {repetition}}} \n {flux}";

            return(task);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a Task label.
        /// </summary>
        /// <param name="label">the label of a Task</param>
        /// <param name="task">a Task of a label</param>
        /// <returns>added label</returns>
        public async Task <Label> AddLabel(Label label, Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));
            Arguments.CheckNotNull(label, nameof(label));

            return(await AddLabel(label.Id, task.Id));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a label from a Task.
        /// </summary>
        /// <param name="label">the label of a Task</param>
        /// <param name="task">a Task of a owner</param>
        /// <returns>delete has been accepted</returns>
        public async System.Threading.Tasks.Task DeleteLabel(Label label, Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));
            Arguments.CheckNotNull(label, nameof(label));

            await DeleteLabel(label.Id, task.Id);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieve list of run records for a task.
        /// </summary>
        /// <param name="task"> task to get runs for</param>
        /// <param name="afterTime">filter runs to those scheduled after this time</param>
        /// <param name="beforeTime">filter runs to those scheduled before this time</param>
        /// <param name="limit">the number of runs to return. Default value: 20.</param>
        /// <returns>the list of run records for a task</returns>
        public async Task <List <Run> > GetRuns(Task task, DateTime?afterTime,
                                                DateTime?beforeTime, int?limit)
        {
            Arguments.CheckNotNull(task, nameof(task));

            return(await GetRuns(task.Id, task.Org, afterTime, beforeTime, limit));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes a owner from a task.
        /// </summary>
        /// <param name="owner">the owner of a task</param>
        /// <param name="task">the task of a owner</param>
        /// <returns>owner removed</returns>
        public async System.Threading.Tasks.Task DeleteOwner(User owner, Task task)
        {
            Arguments.CheckNotNull(task, "task");
            Arguments.CheckNotNull(owner, "owner");

            await DeleteOwner(owner.Id, task.Id);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add a task owner.
        /// </summary>
        /// <param name="owner">the owner of a task</param>
        /// <param name="task">the task of a owner</param>
        /// <returns>created mapping</returns>
        public async Task <ResourceOwner> AddOwner(User owner, Task task)
        {
            Arguments.CheckNotNull(task, "task");
            Arguments.CheckNotNull(owner, "owner");

            return(await AddOwner(owner.Id, task.Id));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes a member from a task.
        /// </summary>
        /// <param name="member">the member of a task</param>
        /// <param name="task">the task of a member</param>
        /// <returns>member removed</returns>
        public async System.Threading.Tasks.Task DeleteMember(User member, Task task)
        {
            Arguments.CheckNotNull(task, "task");
            Arguments.CheckNotNull(member, "member");

            await DeleteMember(member.Id, task.Id);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add a task member.
        /// </summary>
        /// <param name="member">the member of a task</param>
        /// <param name="task">the task of a member</param>
        /// <returns>created mapping</returns>
        public async Task <ResourceMember> AddMember(User member, Task task)
        {
            Arguments.CheckNotNull(task, "task");
            Arguments.CheckNotNull(member, "member");

            return(await AddMember(member.Id, task.Id));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new task. The <see cref="InfluxDB.Client.Api.Domain.Task"/> has to have defined a cron or a every repetition
        /// by the <a href="http://bit.ly/option-statement">option statement</a>.
        /// <example>
        ///     This sample shows how to specify every repetition
        ///     <code>
        /// option task = {
        /// name: "mean",
        /// every: 1h,
        /// }
        ///
        /// from(bucket:"metrics/autogen")
        /// |&gt; range(start:-task.every)
        /// |&gt; group(columns:["level"])
        /// |&gt; mean()
        /// |&gt; yield(name:"mean")
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <Task> CreateTask(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            var status            = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());
            var taskCreateRequest = new TaskCreateRequest(orgID: task.OrgID, org: task.Org, status: status,
                                                          flux: task.Flux, description: task.Description);

            return(await CreateTask(taskCreateRequest));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Update a task. This will cancel all queued runs.
        /// </summary>
        /// <param name="task">task update to apply</param>
        /// <returns>task updated</returns>
        public async Task <Task> UpdateTask(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            var status = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());

            var request = new TaskUpdateRequest(status, task.Flux, task.Name, task.Every, task.Cron);

            return(await UpdateTask(task.Id, request));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Clone a task.
        /// </summary>
        /// <param name="task">task to clone</param>
        /// <returns>cloned task</returns>
        public async Task <Task> CloneTask(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            var status = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), task.Status.ToString());
            var cloned = new TaskCreateRequest(orgID: task.OrgID, org: task.Org, status: status,
                                               flux: task.Flux, description: task.Description);

            return(await CreateTask(cloned).ContinueWith(created =>
            {
                //
                // Add labels
                //
                return GetLabels(task)
                .ContinueWith(labels => { return labels.Result.Select(label => AddLabel(label, created.Result)); })
                .ContinueWith(async tasks =>
                {
                    await System.Threading.Tasks.Task.WhenAll(tasks.Result);
                    return created.Result;
                })
                .Unwrap();
            }).Unwrap());
        }
Exemplo n.º 12
0
        /// <summary>
        /// List all labels of a Task.
        /// </summary>
        /// <param name="task">a Task of the labels</param>
        /// <returns>the List all labels of a Task</returns>
        public async Task <List <Label> > GetLabels(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            return(await GetLabels(task.Id));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieve list of run records for a task.
        /// </summary>
        /// <param name="task"> task to get runs for</param>
        /// <returns>the list of run records for a task</returns>
        public async Task <List <Run> > GetRuns(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            return(await GetRuns(task, null, null, null));
        }
Exemplo n.º 14
0
        /// <summary>
        /// List all owners of a task.
        /// </summary>
        /// <param name="task">task of the owners</param>
        /// <returns>the List all owners of a task</returns>
        public async Task <List <ResourceOwner> > GetOwners(Task task)
        {
            Arguments.CheckNotNull(task, "Task is required");

            return(await GetOwners(task.Id));
        }
Exemplo n.º 15
0
        /// <summary>
        /// List all members of a task.
        /// </summary>
        /// <param name="task">task of the members</param>
        /// <returns>the List all members of a task</returns>
        public async Task <List <ResourceMember> > GetMembers(Task task)
        {
            Arguments.CheckNotNull(task, "task");

            return(await GetMembers(task.Id));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Delete a task.
        /// </summary>
        /// <param name="task">task to delete</param>
        /// <returns>task deleted</returns>
        public async System.Threading.Tasks.Task DeleteTask(Task task)
        {
            Arguments.CheckNotNull(task, nameof(task));

            await DeleteTask(task.Id);
        }