pants icon indicating copy to clipboard operation
pants copied to clipboard

add tail tasks API and use for remote cache writes

Open tdyas opened this issue 1 year ago • 1 comments

Add the concept of "tail tasks" to Pants sessions so that Rust code can schedule async tasks for execution where the tasks should complete before a particular Pants run is considered complete.

First use case: Schedule remote cache writes as tail tasks.

tdyas avatar Sep 21 '22 21:09 tdyas

cc @somdoron

tdyas avatar Sep 21 '22 21:09 tdyas

Just discovered tokio::task::JoinSet which seems relevant.

tdyas avatar Sep 23 '22 19:09 tdyas

There has been some significant refactoring of this PR. It is worth a re-review.

tdyas avatar Sep 26 '22 16:09 tdyas

The latest commits introduce a TailTasks time which encapsulate both spawning and waiting for tail tasks.

tdyas avatar Sep 26 '22 16:09 tdyas

It appears that log_cache_error is not working with tail tasks. https://github.com/pantsbuild/pants/actions/runs/3144144927/jobs/5110386492#step:13:598

I can add regular logging to show that the tail tasks are completing, but errors from log_cache_error are not being displayed.

tdyas avatar Sep 28 '22 20:09 tdyas

It appears that log_cache_error is not working with tail tasks. https://github.com/pantsbuild/pants/actions/runs/3144144927/jobs/5110386492#step:13:598

I can add regular logging to show that the tail tasks are completing, but errors from log_cache_error are not being displayed.

Mmm... that would be because the task local / thread local information is not being propagated to the new task. See the use of Self::future_with_correct_context here: https://github.com/pantsbuild/pants/blob/cdf21fc69954aec999ed57ed988bf67a31148bf9/src/rust/engine/task_executor/src/lib.rs#L121-L137

stuhood avatar Sep 28 '22 20:09 stuhood

Mmm... that would be because the task local / thread local information is not being propagated to the new task. See the use of Self::future_with_correct_context here:

https://github.com/pantsbuild/pants/blob/cdf21fc69954aec999ed57ed988bf67a31148bf9/src/rust/engine/task_executor/src/lib.rs#L121-L137

That was it. Thanks!

It apparently worked in an earlier iteration of the PR only due to the double-spawn, one of which was via Executor which did wrap the task with future_with_correct_context.

tdyas avatar Sep 28 '22 20:09 tdyas