Task creation with Java library

I’m trying to create a task to downsampling a bucket but I am not sure how to set the “option” tag inside of the code.

Error

invalid options: no task options defined

Code

        client.getTasksApi().createTask(new TaskCreateRequest()
                .description("Downsampling statistics to daily statistics.")
                .status(TaskStatusType.ACTIVE)
                .orgID(provider.getOrganizationId())
                .flux(Flux.from("statistics_daily")
                        //Since a day.
                        .range(-1L, ChronoUnit.DAYS)
                        //Aggregate window.
                        .aggregateWindow().withEvery("1d").withAggregateFunction("sum")
                        //Write to infinite bucket.
                        .to("statistics", provider.getOrganizationId(), "(r) => ({sum: r._value})")
                        .toString()));

Solution


        //Creates flux string.
        String flux = """
                option task = {
                    name: "Statistics: Downsampling",
                    every: 1d,
                    offset: 0m
                }
                """;

        //Adds remaining to the string.
        flux += Flux.from("statistics_daily")
                //Since a day.
                .range(-1L, ChronoUnit.DAYS)
                //Aggregate window.
                .aggregateWindow().withEvery("1d").withAggregateFunction("sum")
                //Write to infinite bucket.
                .to("statistics", provider.getOrganizationId(), "(r) => ({sum: r._value})")
                .toString();

        //Creates task.
        client.getTasksApi().createTask(new TaskCreateRequest()
                .description("Downsampling statistics to daily statistics.")
                .status(TaskStatusType.ACTIVE)
                .orgID(provider.getOrganizationId())
                .flux(flux));
1 Like