Skip to content

fix: append task option at the end of script #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 4.5.0 [unreleased]

### Bug Fixes
1. [#348](https://github.com/influxdata/influxdb-client-csharp/pull/348): Append `task option` at the end of script

### Dependencies
Update dependencies:

Expand Down
28 changes: 25 additions & 3 deletions Client.Test/ItTasksApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task CreateTaskCron()
Assert.AreEqual(TaskStatusType.Active, task.Status);
Assert.AreEqual("0 2 * * *", task.Cron);
Assert.IsNull(task.Every);
Assert.IsTrue(task.Flux.EndsWith(TaskFlux, StringComparison.OrdinalIgnoreCase));
StringAssert.StartsWith(TaskFlux, task.Flux);
}

[Test]
Expand All @@ -189,7 +189,7 @@ public async Task CreateTaskEvery()
Assert.AreEqual(TaskStatusType.Active, task.Status);
Assert.AreEqual("1h", task.Every);
Assert.IsNull(task.Cron);
Assert.IsTrue(task.Flux.EndsWith(TaskFlux, StringComparison.OrdinalIgnoreCase));
StringAssert.StartsWith(TaskFlux, task.Flux);
}

[Test]
Expand Down Expand Up @@ -586,7 +586,7 @@ public async Task UpdateTask()
var cronTask =
await _tasksApi.CreateTaskCronAsync(taskName, TaskFlux, "0 2 * * *", _organization);

var flux = $"option task = {{name: \"{taskName}\", every: 3m}}\n\n{TaskFlux}";
var flux = $"{TaskFlux}\n\noption task = {{name: \"{taskName}\", every: 3m}}";

cronTask.Every = "3m";
cronTask.Cron = null;
Expand All @@ -607,5 +607,27 @@ public async Task UpdateTask()

Assert.IsNotNull(updatedTask.UpdatedAt);
}

[Test]
public async Task CreateTaskWithMoreFrom()
{
var taskName = GenerateName("it task");

const string flux = "procTotal = from(bucket: \"example-bucket\")" +
" |> range(start: -5m)" +
" |> filter(fn: (r) => r._measurement == \"processes\" and r._field == \"total\")" +
"" +
"procTotal";

var task = await _tasksApi.CreateTaskCronAsync(taskName, flux, "0 2 * * *", _organization);

Assert.IsNotNull(task);
Assert.IsNotEmpty(task.Id);
Assert.AreEqual(taskName, task.Name);
Assert.AreEqual(_organization.Id, task.OrgID);
Assert.AreEqual(TaskStatusType.Active, task.Status);
Assert.AreEqual("0 2 * * *", task.Cron);
StringAssert.StartsWith(flux, task.Flux);
}
}
}
2 changes: 1 addition & 1 deletion Client/TasksApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ private TaskType CreateTaskAsync(string name, string flux, string every, string
repetition += "\"" + cron + "\"";
}

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

return task;
}
Expand Down