Skip to content
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

Task.lastSuccess does not return last successful task run time #3430 #5498

Open
zcattacz opened this issue Jul 15, 2024 · 3 comments
Open

Task.lastSuccess does not return last successful task run time #3430 #5498

zcattacz opened this issue Jul 15, 2024 · 3 comments

Comments

@zcattacz
Copy link

#3430 still stands in InfluxDB v2.7.7 (git: e9e0f744fa) build_date: 2024-07-11T18:45:02Z
Always return orTime.

@sanderson
Copy link
Contributor

@zcattacz In what context are you running this function? Is it in a task, or just a one-off query?

@zcattacz
Copy link
Author

zcattacz commented Jul 16, 2024

Hi thanks for replying.
I use it in the following script. Which is run in query for debugging and then in task for the job. I intent to reporting for the issue in Task.

import "sql"
import "strings"
import "experimental/array"
import "join"
import "date"
import "influxdata/influxdb/tasks"
import "types"

// without this the webUI for Task wouldn't let me save, 
// "Invalid flux script. Please check your query text."
// though with this the webUI sometimes underlines "task", 
// hinting "Avoid using `task` as an identifier name ... it may be provided at runtime.
// I checked task name is identical.
// not sure if this is related or what is the right way to handle this
option task = {name: "cq_mstat_5m", every: 5m, offset: 30s}

cnlTbl =
    sql.from(
        driverName: "postgres",
        dataSourceName: "postgresql://...",
        query:"...",
    )

arrCnls =
    cnlTbl
        |> tableFind(fn: (key) => true)
        |> getColumn(column: "cnl_num")

_tDstEnd =
    from(bucket: "cache_mach_stat_5m")
        |> range(start: time(v: "2020-01-01T00:00:00.00Z"))
        |> max(column: "_time")
        |> last(column: "_time")
        |> tableFind(fn: (key) => true)
        |> getColumn(column: "_time")
tDstEnd = _tDstEnd[0]

//_tPrevTaskSucc =
//    from(bucket: "cq_task_param")
//        |> range(start: time(v: "2020-01-01T00:00:00Z"))
//        |> filter(fn: (r) => r._measurement == "cq_mstat_5m" and r._field == "lastSucc")
//        |> sort(columns: ["_time"], desc: true)
//        |> first()
//        |> tableFind(fn: (key) => true)
//        |> getColumn(column: "_time")

//It was,
tPrevTaskSucc = tasks.lastSuccess(orTime: tDstEnd)

//tPrevTaskSucc = _tPrevTaskSucc[0]

tDstEnd1 =
    if tDstEnd < tPrevTaskSucc then
        date.add(d: 7d, to: tDstEnd)
    else
        date.add(d: task.every, to: tPrevTaskSucc)

array.from(
    rows: [
        {"_time": now(), "_field": "tPrevTaskSucc", "_value": tPrevTaskSucc},
        //{"_time": now(), "_field": "tDstEnd", "_value": tDstEnd},
        //{"_time": now(), "_field": "tSrcEnd", "_value": tSrcEnd[0]},
    ],
)
    |> set(key: "_measurement", value: "rplc_cq")
    |> to(bucket: "rplc1_cq_param")

//...

I add this as task then manually repeatedly executed for a few times, the WebUI always report success, later when I check the rplc1_cq_param bucket, tPrevTaskSucc is always the same value.

Copy link

This issue has had no recent activity and will be closed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants