Run task in specific timezone time

Hi,

need to create alert if I don’t have any payment till noon in specific timezone (Influx OSS v2.7).

trying to do it through task (code below),
but as we don’t have possibility to start task in specific timezone,
need to calculate offset between my specific timezone and UTC considering DST on the task side, to use it in task option as start offset.

in this post

was mentioned that timezone.location change now() to timezone time, but test this on

utcNow = now()
option location = timezone.location(name: "Europe/Kiev")
kyivNow = now()
offset = duration(v: utcNow - kyivNow)

and utcNow, kyivNow - I have same utc time.

Exists any possibility to obtain timezone offset on task level?

option location = timezone.location(name: "Europe/Kiev")
option task = {name: "No payments till noon", cron: "0 12 * * *", offset: -2h}

paymentAttempts =
    from(bucket: v.bucket)
        |> range(start: -12h)
        |> filter(fn: (r) => r["_measurement"] == "payment_attempt")
        |> aggregateWindow(every: 12h, fn: count, createEmpty: false)
        |> group(columns: [])
        |> sum()
        |> yield(name: "no payment till noon")

paymentAttempts
     |> filter(fn: (r) => r._value == 0)

slack.message(
...

You can shift the queries and get data for a particular timezone and you can adjust the offset to get it to run at the start of your day like you’ve done. The timezone affects how time is interpreted within the Flux script, but not when the task itself runs. But you can’t get the offset value afaik. You’ll have to offset it manually I believe. For your specific use case of checking payments by noon in a specific timezone, you can use the offset parameter in aggregateWindow() to shift window boundaries as well.

So said another way, for your specific requirement to check for payments by noon in Kiev time:

  1. Use a cron expression to run at UTC time that corresponds to noon in your timezone
  2. In your Flux script, use the timezone option to ensure proper time interpretation
  3. Use the appropriate range and filter to check for payments