Hi everyone I have a question about the GraphQL AP...
# ask-community
e
Hi everyone I have a question about the GraphQL API Is there a way to get the latest log message from a task by RUN_ID?
s
By task do you mean step? It is possible to access compute logs by step key (typically the op name) using the GQL API. I think this should do it:
Copy code
runOrError(runId: $myRunId) {
  ... on Run {
    computeLogs(stepKey: $myStepKey) {
      stdout {
        data
      }
    }
  }
}
e
Thank you. By task I mean run
Copy code
query LogsForRun($runId: ID!){
  logsForRun (runId: $runId, limit:10) {
    __typename
    ... on EventConnection {
      events {
        ... on LogMessageEvent {
          runId
          message
          timestamp
          stepKey
        }
      }
    }
  }
}
This query returns first 10. My goal is to get the latest one
s
ah I see, I don’t think there’s a way to do that right now, but I can look into adding an argument that reverses the sort order, which IIUC would help you get what you want
e
Awesome! Thank you! Basically my final goal is to create a script to kill frozen runs processes (frozen - a run which gets stuck but still showing STARTED status) I thought I can get the latest timestamp from the LogMessageEvent, and check if it’s greater than defined timeout, Terminate the run Is this something similar to
max_resume_run_attempts
?
Copy code
# Opt in to the experimental Monitoring Daemon
run_monitoring:
  enabled: true
  # values below are the defaults, and don't need to be specified execpt to override them
  start_timeout_seconds: 180
  max_resume_run_attempts: 3 # experimental if above 0
  poll_interval_seconds: 120
I’m using
DockerRunLauncher