Task Query Issue

Hi,

I am facing some issue to create a query for task.

My Query is like -

import "influxdata/influxdb/monitor"
import "slack"
import "json"
slack_endpoint = slack["endpoint"](url: "https://hooks.slack.com/services/xxx")
data_1 = from(bucket: "TESTDB")
  |> range(start: -10h)
  |> filter(fn: (r) => r["_measurement"] == "sensor_data_cae3a96f116847d7a437ac3d469abb98")
  |> pivot(rowKey:["_time"],columnKey: ["_field"],valueColumn: "_value")
  |> filter(fn: (r) => r["assetId"] == "be9f90fe47a81b2118d0f84ec5006798")
  |> filter(fn: (r) => r["spo2"] > 102)
  |> aggregateWindow(every: 10h, fn: mean, createEmpty: false, column: "spo2")
  |> filter(fn: (r) => r["spo2"] > 105)
  |> keep(columns: ["_time","assetId", "spo2"])

data_2 = from(bucket: "TESTDB")
  |> range(start: -1d)
  |> filter(fn: (r) => r["_measurement"] == "sensor_data_28c352a063c2b864f5abed35237228f5")
  |> pivot(rowKey:["_time"],columnKey: ["_field"],valueColumn: "_value")
  |> filter(fn: (r) => r["assetId"] == "be9f90fe47a81b2118d0f84ec5006798")
  |> filter(fn: (r) => r["glucose_level"] > 100)
  |> aggregateWindow(every: 10h, fn: count, createEmpty: false, column: "glucose_level")
  |> filter(fn: (r) => r["glucose_level"] > 1)
  |> keep(columns: ["_time","assetId", "glucose_level"])

join(
    tables: {d1: data_1, d2: data_2},
    on: ["assetId"],
    )
    |> map(fn: (r) => ({ r with
     jsonStr: string(v: json.encode(v: {"SPo2":r.spo2,"Glucose_Level":r.glucose_level,"assetId":r.assetId}))}))
     |> monitor["notify"](data: {}, endpoint: slack_endpoint(mapFn: (r) =>
     ({channel: "", text: r["jsonStr"], color: "danger"})))

I am trying put that into task. When i tried to execute from data explorer query its firing the slack endpoint which is expected but showing some runtime error.

My task query is like -

import "influxdata/influxdb/monitor"
import "slack"
import "json"
option task = {name: "TEST TASK", every: 1m, offset: 5s}
slack_endpoint = slack["endpoint"](url: "https://hooks.slack.com/services/xxx")
data_1 = from(bucket: "TESTDB")
  |> range(start: -10h)
  |> filter(fn: (r) => r["_measurement"] == "sensor_data_cae3a96f116847d7a437ac3d469abb98")
  |> pivot(rowKey:["_time"],columnKey: ["_field"],valueColumn: "_value")
  |> filter(fn: (r) => r["assetId"] == "be9f90fe47a81b2118d0f84ec5006798")
  |> filter(fn: (r) => r["spo2"] > 102)
  |> aggregateWindow(every: 10h, fn: mean, createEmpty: false, column: "spo2")
  |> filter(fn: (r) => r["spo2"] > 105)
  |> keep(columns: ["_time","assetId", "spo2"])

data_2 = from(bucket: "TESTDB")
  |> range(start: -1d)
  |> filter(fn: (r) => r["_measurement"] == "sensor_data_28c352a063c2b864f5abed35237228f5")
  |> pivot(rowKey:["_time"],columnKey: ["_field"],valueColumn: "_value")
  |> filter(fn: (r) => r["assetId"] == "be9f90fe47a81b2118d0f84ec5006798")
  |> filter(fn: (r) => r["glucose_level"] > 100)
  |> aggregateWindow(every: 10h, fn: count, createEmpty: false, column: "glucose_level")
  |> filter(fn: (r) => r["glucose_level"] > 1)
  |> keep(columns: ["_time","assetId", "glucose_level"])

join(
    tables: {d1: data_1, d2: data_2},
    on: ["assetId"],
    )
    |> map(fn: (r) => ({ r with
    jsonStr: string(v: json.encode(v: {"SPo2":r.spo2,"Glucose_Level":r.glucose_level,"assetId":r.assetId}))}))
    |> monitor["notify"](data: {}, endpoint: slack_endpoint(mapFn: (r) =>
    ({channel: "", text: r["jsonStr"], color: "danger"})))

Showing the same error for the task as well.

Can you please rectify me. It will be very helpful.
Please help @Anaisdg @samdillard

Thank you.

Hi,

Can anyone please help with that issue. Actually i stuck with that and unable to move forward. Once it solved then will do the rest tasks. Any help will be appreciated.