Repository: unionlabs/union
File: hubble/src/indexer/mod.rs (Rust)

Code before:
            {
                Some(fetcher_client) => {
                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_fetcher(fetcher_client_clone).await }
                            .instrument(info_span!("fetcher")),
                    );

                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_finalizer(fetcher_client_clone).await }
                            .instrument(info_span!("finalizer")),
                    );

                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_fixer(fetcher_client_clone).await }
                            .instrument(info_span!("fixer")),
                    );

                    if let EndOfRunResult::Exit = self
                        .handle_end_of_run(&mut join_set, fetcher_client)
                        .instrument(info_span!("exiter"))
                        .await?
                    {
                        return Ok(());
                    }
                }
                None => {
                    // can't create client => try again later
                    sleep(Duration::from_millis(1000)).await;
                }
            }
        }
    }

    async fn create_fetcher_client(
        &self,
        join_set: &mut JoinSet<Result<(), IndexerError>>,
        context: T::Context,
    ) -> Option<T> {
        info!("creating client (context: {})", self.context);
        match T::create(self.pg_pool.clone(), join_set, context).await {
            Ok(client) => {
                info!("created client: {}", client);
                Some(client)
            }
            Err(error) => {

Review comment (suggestion):
probably good to include some context in these spans as well? something like `info_span!(context = %self.context, "fetcher")`

Code after:
            {
                Some(fetcher_client) => {
                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_fetcher(fetcher_client_clone).await }
                            .instrument(info_span!("fetcher")),
                    );

                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_finalizer(fetcher_client_clone).await }
                            .instrument(info_span!("finalizer")),
                    );

                    let self_clone = self.clone();
                    let fetcher_client_clone = fetcher_client.clone();
                    join_set.spawn(
                        async move { self_clone.run_fixer(fetcher_client_clone).await }
                            .instrument(info_span!("fixer")),
                    );

                    if let EndOfRunResult::Exit = self
                        .handle_end_of_run(&mut join_set, fetcher_client)
                        .instrument(info_span!("terminator"))
                        .await?
                    {
                        return Ok(());
                    }
                }
                None => {
                    // can't create client => try again later
                    sleep(Duration::from_millis(1000)).await;
                }
            }
        }
    }

    async fn create_fetcher_client(
        &self,
        join_set: &mut JoinSet<Result<(), IndexerError>>,
        context: T::Context,
    ) -> Option<T> {
        info!("creating client (context: {})", self.context);
        match T::create(self.pg_pool.clone(), join_set, context).await {
            Ok(client) => {
                info!("created client: {}", client);
                Some(client)
            }
            Err(error) => {