wip: more tracing, sleep at first
This commit is contained in:
parent
c481c9beb6
commit
1c83c37f4e
|
@ -196,6 +196,7 @@ pub async fn enqueue_paths(state: &State, store_paths: Vec<StorePath>) -> Result
|
|||
|
||||
/// Refresh the GitHub Actions JWT every 2 minutes (slightly less than half of the default validity
|
||||
/// period) to ensure pushing / pulling doesn't stop working.
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn refresh_github_actions_jwt_worker(
|
||||
netrc_path: std::path::PathBuf,
|
||||
mut github_jwt: String,
|
||||
|
@ -207,6 +208,10 @@ async fn refresh_github_actions_jwt_worker(
|
|||
// breaks this.
|
||||
let next_refresh = std::time::Duration::from_secs(2 * 60);
|
||||
|
||||
// NOTE(cole-h): we sleep until the next refresh at first because we already got a token from
|
||||
// GitHub recently, don't need to try again until we actually might need to get a new one.
|
||||
tokio::time::sleep(next_refresh).await;
|
||||
|
||||
// NOTE(cole-h): https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-cloud-providers#requesting-the-jwt-using-environment-variables
|
||||
let mut headers = reqwest::header::HeaderMap::new();
|
||||
headers.insert(
|
||||
|
@ -257,6 +262,7 @@ async fn refresh_github_actions_jwt_worker(
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn rewrite_github_actions_token(
|
||||
client: &reqwest::Client,
|
||||
netrc_path: &Path,
|
||||
|
@ -319,7 +325,9 @@ async fn rewrite_github_actions_token(
|
|||
"symlink_metadata(netrc_path): {:?}",
|
||||
tokio::fs::symlink_metadata(&netrc_path).await
|
||||
);
|
||||
|
||||
let new_netrc_contents = netrc_contents.replace(old_github_jwt, &new_github_jwt_string);
|
||||
|
||||
// NOTE(cole-h): create the temporary file right next to the real one so we don't run into
|
||||
// cross-device linking issues when renaming
|
||||
let netrc_path_tmp = netrc_path.with_extension("tmp");
|
||||
|
@ -335,6 +343,7 @@ async fn rewrite_github_actions_token(
|
|||
"symlink_metadata(netrc_path_tmp): {:?}",
|
||||
tokio::fs::symlink_metadata(&netrc_path_tmp).await
|
||||
);
|
||||
|
||||
tokio::fs::rename(&netrc_path_tmp, &netrc_path)
|
||||
.await
|
||||
.with_context(|| format!("renaming {netrc_path_tmp:?} to {netrc_path:?}"))?;
|
||||
|
|
Loading…
Reference in a new issue