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

let TaskRunRecorder process events into task runs/task run states #14729

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

jakekaplan
Copy link
Contributor

closes: #14648

Updates TaskRunRecorder from being a no-op service to actually processing task-run events that come through.

For every event we see we'll:

  • insert or update the task run
  • insert the task run state
  • update the task run with the state data

@jakekaplan jakekaplan requested a review from cicdw as a code owner July 24, 2024 13:47
}
session = await stack.enter_async_context(db.session_context())

await _insert_task_run(session, task_run, task_run_attributes)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately due to FK's we need to insert the task run, then insert the task run state, then go back and update the task run with the denormalized state attributes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sometimes this trips me up with the db.session_context(): begin_transaction defaults to False, so these aren't in a transaction, right? It feels like they should be

Copy link
Contributor Author

@jakekaplan jakekaplan Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ 100% yes, great catch. Should I set db.session_context(..., with_for_update=True) as well here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, that might make the lock a little more aggressive? I'm thinking about the SQLite implementation hitting database is locked. Since this should be the only thing writing task runs, I think we're good with just the transaction

db.TaskRun.id == task_run.id,
sa.or_(
db.TaskRun.state_timestamp.is_(None),
db.TaskRun.state_timestamp < task_run.state.timestamp,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fits our pattern so that we'll only do this if things are in order

Copy link

codspeed-hq bot commented Jul 24, 2024

CodSpeed Performance Report

Merging #14729 will not alter performance

Comparing oss-task-run-recorder (26e74d5) with main (44e7ebe)

Summary

✅ 5 untouched benchmarks

Copy link
Collaborator

@chrisguidry chrisguidry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just that one question about the transaction, but it looks great!

}
session = await stack.enter_async_context(db.session_context())

await _insert_task_run(session, task_run, task_run_attributes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sometimes this trips me up with the db.session_context(): begin_transaction defaults to False, so these aren't in a transaction, right? It feels like they should be

@jakekaplan jakekaplan merged commit 262433c into main Jul 24, 2024
30 of 31 checks passed
@jakekaplan jakekaplan deleted the oss-task-run-recorder branch July 24, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create task runs from task run events
2 participants