-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: I was putting everything in `sync-loop` cause that's the main command to be used, but if we want to reuse this in, e.g `sync-once` that would be nested user a bunch of unnecessary stuff, so pulling it out (also, keeping files small for my own sanity) Reviewed By: andreacampi Differential Revision: D65541266 fbshipit-source-id: 7a23294a98358265a3cb1165adf8c57c780a3067
- Loading branch information
1 parent
3582448
commit 740bd93
Showing
3 changed files
with
61 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This software may be used and distributed according to the terms of the | ||
* GNU General Public License version 2. | ||
*/ | ||
|
||
use std::sync::Arc; | ||
|
||
use anyhow::format_err; | ||
use anyhow::Result; | ||
use clientinfo::ClientEntryPoint; | ||
use clientinfo::ClientInfo; | ||
use context::CoreContext; | ||
use mononoke_app::args::RepoArg; | ||
use mononoke_app::MononokeApp; | ||
use mutable_counters::MutableCountersRef; | ||
use repo_identity::RepoIdentityRef; | ||
use slog::info; | ||
|
||
use crate::Repo; | ||
const MODERN_SYNC_COUNTER_NAME: &str = "modern_sync"; | ||
|
||
pub async fn sync( | ||
app: Arc<MononokeApp>, | ||
start_id_arg: Option<i64>, | ||
repo_arg: RepoArg, | ||
) -> Result<()> { | ||
let repo: Repo = app.open_repo(&repo_arg).await?; | ||
let _repo_id = repo.repo_identity().id(); | ||
let repo_name = repo.repo_identity().name().to_string(); | ||
|
||
let ctx = CoreContext::new_with_logger_and_client_info( | ||
app.fb, | ||
app.logger().clone(), | ||
ClientInfo::default_with_entry_point(ClientEntryPoint::ModernSync), | ||
) | ||
.clone_with_repo_name(&repo_name); | ||
|
||
let start_id = start_id_arg.unwrap_or( | ||
repo.mutable_counters() | ||
.get_counter(&ctx, MODERN_SYNC_COUNTER_NAME) | ||
.await? | ||
.ok_or_else(|| { | ||
format_err!( | ||
"No start-id or mutable counter {} provided", | ||
MODERN_SYNC_COUNTER_NAME | ||
) | ||
})?, | ||
); | ||
|
||
info!(app.logger(), "Starting with value {}", start_id); | ||
|
||
Ok(()) | ||
} |