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

Replace task run() return result with custom enum #2429

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MitchTurner
Copy link
Member

@MitchTurner MitchTurner commented Nov 12, 2024

Linked Issues/PRs

N/A

Description

Before any RunnableTask would return a Result<bool> where, implicitly, the bool was telling the service runner if it should re-run the task.

This is confusing from the customer perspective since you need to understand the behavior of ServiceRunner in order to choose the right response: i.e. Ok(true) meant you want to rerun. Instead this PR adds the Continue and Stop variants.

It was also confusing with Error since, unintuitively, an Error would result in the task being run again. This PR adds the ErrorContinue variant, so the implementer know explicitly what the behavior is.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@@ -137,8 +138,7 @@ impl RunnableService for SyncTask {

#[async_trait::async_trait]
impl RunnableTask for SyncTask {
#[tracing::instrument(level = "debug", skip_all, err, ret)]
Copy link
Member Author

@MitchTurner MitchTurner Nov 12, 2024

Choose a reason for hiding this comment

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

Had to remove this from a couple locations since the instrument macro assumes the function returns Result

@@ -196,11 +197,15 @@ impl RunnableService for GraphqlService {

#[async_trait::async_trait]
impl RunnableTask for Task {
async fn run(&mut self, _: &mut StateWatcher) -> anyhow::Result<bool> {
self.server.as_mut().await?;
Copy link
Member Author

Choose a reason for hiding this comment

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

This change introduces a non-trivial amount of noise with the removal of the ? operators.

AFAICT, there isn't a way to implement Try for arbitrary types in Rust which is a real bummer.

@MitchTurner MitchTurner marked this pull request as ready for review November 12, 2024 11:26
}
}
}
should_continue = true;
}
}

Ok(should_continue)
TaskRunResult::should_continue(should_continue)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I though the idea was to remove should_continue variable and replace with the usage of the enum=D

let da_block_costs = self.source.request_da_block_cost().await?;
self.shared_state.0.send(da_block_costs)?;
continue_running = true;
match self.source.request_da_block_cost().await.and_then(|da_block_costs| self.shared_state.0.send(da_block_costs).map_err(|err| anyhow::anyhow!(err))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is very hard to read, maybe we could it inside of the function and process the result of the function?=)

Comment on lines +134 to +139
let block = match l2_block_res {
Ok(block) => block,
Err(err) => {
return anyhow!(err).into()
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this pattern in many places. Maybe it would be simpler to defined a helper trait with into_continue_task_result which either returns TaskRunResult::Continue or TaskRunResult::ErrorContinue

@MitchTurner MitchTurner self-assigned this Nov 14, 2024
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.

2 participants