Skip to content

Commit

Permalink
don't override the manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
lostman committed Dec 8, 2023
1 parent fefbf2c commit e60b43b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 56 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 7 additions & 16 deletions packages/fuel-indexer-benchmarks/src/bin/qa.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use chrono::Utc;
use clap::Parser;
use duct::cmd;
use fuel_indexer_lib::{
config::IndexerConfig, defaults, manifest::Manifest, utils::init_logging,
};
use fuel_indexer_lib::{config::IndexerConfig, defaults, utils::init_logging};
use reqwest::{
header::{HeaderMap, CONTENT_TYPE},
Client,
Expand Down Expand Up @@ -532,8 +530,6 @@ async fn main() {
let explorer_root =
canonicalize(examples_root.join("fuel-explorer").join("fuel-explorer")).unwrap();

let mani_path = explorer_root.join("fuel_explorer.manifest.yaml");

let _proc = Command::new("forc-index")
.arg("start")
.arg("--run-migrations")
Expand Down Expand Up @@ -564,7 +560,6 @@ async fn main() {
"Performing {num_runs} runs, indexing {blocks_per_run} blocks per run."
);
tracing::info!("Start blocks: {start_blocks:?}");
let manifest = Manifest::from_file(&mani_path).unwrap();
let mut stats = StatManager::new();

// Deploy some number of additional hello-world indexers.
Expand All @@ -573,20 +568,18 @@ async fn main() {
// performance when multiple indexers are running at the same time - if the user so specifies.
if let Some(num_additional_indexers) = opts.num_additional_indexers {
let hello_world_root = examples_root.join("hello-world").join("hello-world");
let mani_path = hello_world_root.join("hello_world.manifest.yaml");
let mut manifest = Manifest::from_file(&mani_path).unwrap();

for i in 0..num_additional_indexers {
tracing::info!("Deploying additional indexer #{}", i + 1);
manifest.set_identifier(format!("hello_world_{}", i));
let _ = manifest.write(&mani_path).unwrap();

sleep(Duration::from_secs(1)).await;

let mut proc = Command::new("forc-index")
.arg("deploy")
.arg("--path")
.arg(&hello_world_root.to_str().unwrap())
.arg("--override-identifier")
.arg::<String>(format!("hello_world_{}", i))
.spawn()
.unwrap();

Expand All @@ -607,13 +600,7 @@ async fn main() {
let end_block = start_block + blocks_per_run;
let mut run_stats = RunStat::new(run, *start_block, end_block);

let mut manifest = manifest.clone();

tracing::info!("Run {run} will index block #{start_block} - #{end_block}",);
manifest.set_start_block(*start_block);

manifest.set_end_block(end_block);
let _ = manifest.write(&mani_path).unwrap();

sleep(Duration::from_secs(1)).await;

Expand All @@ -622,6 +609,10 @@ async fn main() {
.arg("--path")
.arg(&explorer_root.to_str().unwrap())
.arg("--replace-indexer")
.arg("--override-start-block")
.arg(start_block.to_string())
.arg("--override-end-block")
.arg(end_block.to_string())
.spawn()
.unwrap();

Expand Down
14 changes: 1 addition & 13 deletions packages/fuel-indexer-lib/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Write},
io::Read,
path::{Path, PathBuf},
str::FromStr,
};
Expand Down Expand Up @@ -147,18 +147,6 @@ impl Manifest {
}
}

/// Write this manifest to a given path.
pub fn write(&self, path: &PathBuf) -> ManifestResult<()> {
let mut file = File::create(path).map_err(|err| {
ManifestError::FileError(path.to_str().unwrap_or_default().to_string(), err)
})?;
let content: Vec<u8> = Self::into(self.clone());
file.write_all(&content).map_err(|err| {
ManifestError::FileError(path.to_str().unwrap_or_default().to_string(), err)
})?;
Ok(())
}

/// Set the start block for this indexer.
pub fn set_start_block(&mut self, block: u32) {
self.start_block = Some(block);
Expand Down
12 changes: 12 additions & 0 deletions plugins/forc-index/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ pub struct Command {
/// Enable verbose output.
#[clap(short, long, help = "Enable verbose output.")]
pub verbose: bool,

/// Override the start block
#[clap(long, help = "Override the start block.")]
pub override_start_block: Option<u32>,

/// Override the end block
#[clap(long, help = "Override the end blockt.")]
pub override_end_block: Option<u32>,

/// Override the identifier
#[clap(long, help = "Override the identifier.")]
pub override_identifier: Option<String>,
}

pub fn exec(command: Command) -> Result<()> {
Expand Down
12 changes: 12 additions & 0 deletions plugins/forc-index/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ pub struct Command {
help = "Remove all indexed data when replacing an existing indexer."
)]
pub remove_data: bool,

/// Override the start block
#[clap(long, help = "Override the start block.")]
pub override_start_block: Option<u32>,

/// Override the end block
#[clap(long, help = "Override the end blockt.")]
pub override_end_block: Option<u32>,

/// Override the identifier
#[clap(long, help = "Override the identifier.")]
pub override_identifier: Option<String>,
}

pub async fn exec(command: Command) -> Result<()> {
Expand Down
23 changes: 12 additions & 11 deletions plugins/forc-index/src/ops/forc_index_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
locked,
manifest,
verbose,
override_start_block,
override_end_block,
override_identifier,
..
} = command;

Expand Down Expand Up @@ -56,6 +59,15 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
let indexer_manifest_path = root_dir.join(manifest);
let mut manifest = Manifest::from_file(&indexer_manifest_path)?;

if let Some(start_block) = override_start_block {
manifest.set_start_block(start_block)
}
if let Some(end_block) = override_end_block {
manifest.set_end_block(end_block)
}
if let Some(identifier) = override_identifier {
manifest.set_identifier(identifier)
}
let manifest_schema_file = {
let workspace_root: std::path::PathBuf =
crate::utils::cargo_workspace_root_dir(path.as_path()).unwrap();
Expand Down Expand Up @@ -172,15 +184,7 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
.join(profile)
.join(&binary);

let rel_artifact_path = Path::new("target")
.join(defaults::WASM_TARGET)
.join(profile)
.join(&binary);

let abs_wasm = abs_artifact_path.as_path().display().to_string();
let relative_wasm = rel_artifact_path.as_path().display().to_string();

manifest.set_module(Module::Wasm(relative_wasm));

let status = Command::new("wasm-snip")
.arg(&abs_wasm)
Expand All @@ -198,9 +202,6 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
anyhow::bail!("❌ Failed to execute wasm-snip: (Code: {code:?})",)
}

// FIXME: This should include whatever comments were in the original doc
manifest.write(&indexer_manifest_path)?;

Ok(())
}

Expand Down
6 changes: 6 additions & 0 deletions plugins/forc-index/src/ops/forc_index_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub async fn init(command: DeployCommand) -> anyhow::Result<()> {
replace_indexer,
remove_data,
skip_build,
override_start_block,
override_end_block,
override_identifier,
} = command;

if !skip_build {
Expand All @@ -38,6 +41,9 @@ pub async fn init(command: DeployCommand) -> anyhow::Result<()> {
debug,
verbose,
locked,
override_start_block,
override_end_block,
override_identifier,
})?;
}

Expand Down

0 comments on commit e60b43b

Please sign in to comment.