creating/updating task with leading import statement not working
tost11 opened this issue · 1 comments
Steps to reproduce:
Create a task with leading import statement
client.getTasksApi().createTaskCron("whatever",fluxQuery,"10 0 * * * *","01feb3ff2a370ff0");
fluxQuery like so:
import "experimental"
from(bucket: "user-1")
|> range(start: experimental.addDuration(d: -1d, to: today()), stop: today())
|> filter(fn: (r) => r["system"] == "2")
|> filter(fn: (r) => r["_field"] == "ChargeWatt" or r["_field"] == "Duration")
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({r with _value: r.ChargeWatt * r.Duration / 1000.0 / 60.0}))
|> cumulativeSum()
|> max()
|> map(fn: (r) => ({r with _time: today(), _measurement: "day-values", _field: "outcome"}))
It seems the flux query is generated wrong.
The additional options seems to be added before the import statement:
option task = {name: "whatever", cron: "12 0 * * * *"}
import "experimental"
from(bucket: "user-1")
|> ...
It should be:
import "experimental"
option task = {name: "whatever", cron: "12 0 * * * *"}
from(bucket: "user-1")
|> ...
also the updateTask functions are not working
also could it be that on TaskCreateRequest the name attribute is missing some creation functions didn't work because of that
Expected behavior:
Create a new Task.
Actual behavior:
Error from influx because import statement is not allowed at this position
"invalid options: loc 2:2-2:8: invalid statement @2:2-2:8: import"
Specifications:
- Client Version: 5.0.0
- InfluxDB Version: 2.2
- JDK Version: java-1.11.0-openjdk-amd64
- Platform: Linux
Hi @tost11,
thanks for using our client.
Error from influx because import statement is not allowed at this position
"invalid options: loc 2:2-2:8: invalid statement @2:2-2:8: import"
As a workaround please use the TaskApi.createTask(@Nonnull final TaskCreateRequest taskCreateRequest) method to create task. Something like following code will be works:
String taskFlux = "import \"experimental\"\n"
+ "\n"
+ "option task = {name: \"whatever\", cron: \"12 0 * * * *\"}"
+ "\n"
+ "from(bucket: \"my-bucket\")\n"
+ " |> range(start: experimental.addDuration(d: -1d, to: today()), stop: today())\n"
+ " |> max()";
TaskCreateRequest taskCreateRequest = new TaskCreateRequest()
.orgID(organization.getId())
.flux(taskFlux)
.status(TaskStatusType.ACTIVE);
Task task = tasksApi.createTask(taskCreateRequest);
also could it be that on TaskCreateRequest the name attribute is missing some creation functions didn't work because of that
You have to specify the name in option
part . The TaskCreateRequest
definition doesn't contains name
attribute - https://docs.influxdata.com/influxdb/v2.2/api/#operation/PostTasks.
Regards