-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: master
Are you sure you want to change the base?
Conversation
@@ -137,8 +138,7 @@ impl RunnableService for SyncTask { | |||
|
|||
#[async_trait::async_trait] | |||
impl RunnableTask for SyncTask { | |||
#[tracing::instrument(level = "debug", skip_all, err, ret)] |
There was a problem hiding this comment.
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?; |
There was a problem hiding this comment.
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.
} | ||
} | ||
} | ||
should_continue = true; | ||
} | ||
} | ||
|
||
Ok(should_continue) | ||
TaskRunResult::should_continue(should_continue) |
There was a problem hiding this comment.
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))) { |
There was a problem hiding this comment.
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?=)
let block = match l2_block_res { | ||
Ok(block) => block, | ||
Err(err) => { | ||
return anyhow!(err).into() | ||
} | ||
}; |
There was a problem hiding this comment.
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
Linked Issues/PRs
N/A
Description
Before any
RunnableTask
would return aResult<bool>
where, implicitly, thebool
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 theContinue
andStop
variants.It was also confusing with
Error
since, unintuitively, anError
would result in the task being run again. This PR adds theErrorContinue
variant, so the implementer know explicitly what the behavior is.Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]