Skip to content

Commit

Permalink
fix: failed typegraph deployment (#758)
Browse files Browse the repository at this point in the history
<!--
Pull requests are squashed and merged using:
- their title as the commit message
- their description as the commit body

Having a good title and description is important for the users to get
readable changelog.
-->

<!-- 1. Explain WHAT the change is about -->

- Fix casing typo in the typescript sdk
- Fix error reporting in the typescript sdk
- Display the retry number
- Warning on cancelled retry

<!-- 2. Explain WHY the change cannot be made simpler -->

<!-- 3. Explain HOW users should update their code -->

#### Migration notes

N/A

- [ ] The change comes with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
Natoandro authored Jun 18, 2024
1 parent 509b61b commit 0890198
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
5 changes: 4 additions & 1 deletion examples/metatype.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
typegates:
dev:
url: "http://localhost:7890"
url: "http://localhost:7891"
username: admin
password: password
secrets:
Expand Down Expand Up @@ -156,6 +156,9 @@ typegraphs:
- "typegraphs/temporal.ts"
include:
- "typegraphs/*.ts"
javascript:
exclude:
- "**/*"

metagen:
targets:
Expand Down
17 changes: 16 additions & 1 deletion meta-cli/src/deploy/actors/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::config::Config;
use crate::deploy::actors::task_io::TaskIoActor;
use crate::interlude::*;
use action::{get_typegraph_name, TaskActionGenerator};
use colored::OwoColorize;
use common::typegraph::Typegraph;
use indexmap::IndexMap;
use process_wrap::tokio::TokioChildWrapper;
Expand Down Expand Up @@ -94,6 +95,7 @@ pub struct TaskActor<A: TaskAction + 'static> {
console: Addr<ConsoleActor>,
results: IndexMap<String, ActionResult<A>>, // for the report
timeout_duration: Duration,
max_retry_count: usize, // for the progress display
}

impl<A> TaskActor<A>
Expand All @@ -106,6 +108,7 @@ where
initial_action: A,
task_manager: Addr<TaskManager<A>>,
console: Addr<ConsoleActor>,
max_retry_count: usize,
) -> Self {
Self {
config,
Expand All @@ -128,6 +131,7 @@ where
})
.unwrap_or(DEFAULT_TIMEOUT),
),
max_retry_count,
}
}

Expand Down Expand Up @@ -180,7 +184,18 @@ impl<A: TaskAction + 'static> Handler<StartProcess> for TaskActor<A> {

fn handle(&mut self, StartProcess(cmd): StartProcess, ctx: &mut Context<Self>) -> Self::Result {
use process_wrap::tokio::*;
self.console.info(self.action.get_start_message());
let retry_no = self.action.get_task_ref().retry_no;
let retry_progress = if retry_no > 0 {
let max_retry = self.max_retry_count;
format!(" (retry {retry_no}/{max_retry})")
} else {
"".to_string()
};
self.console.info(format!(
"{}{}",
self.action.get_start_message(),
retry_progress.dimmed()
));
let spawn_res = TokioCommandWrap::from(cmd)
.wrap(KillOnDrop)
// we use sessions so that kill on drop
Expand Down
13 changes: 11 additions & 2 deletions meta-cli/src/deploy/actors/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::task::action::{TaskAction, TaskActionGenerator};
use super::task::{self, TaskActor, TaskFinishStatus};
use super::watcher::WatcherActor;
use crate::{config::Config, interlude::*};
use colored::OwoColorize;
use futures::channel::oneshot;
use indexmap::IndexMap;
use signal_handler::set_stop_recipient;
Expand Down Expand Up @@ -306,19 +307,26 @@ impl<A: TaskAction + 'static> Handler<AddTask> for TaskManager<A> {
if msg.task_ref.retry_no > 0 {
if let Some(retry_task_id) = pending_retry_id {
if retry_task_id != msg.task_ref.id {
// unreachable
self.console.warning(
"invalid state: different task id for retry; cancelling".to_string(),
);
return;
}
// ok
// ok: this task is a retry
} else {
self.console
.warning("invalid state: unregistered retry; cancelling".to_string());
return;
}
} else if pending_retry_id.is_some() {
// ok: this task is not a retry; pending retry cancelled
self.console.warning(format!(
"pending retry task for {path} cancelled",
path = msg.task_ref.path.display().to_string().yellow(),
));
} else {
// retry cancelled
// ok: new task
}

self.task_queue.push_back(msg.task_ref);
Expand Down Expand Up @@ -361,6 +369,7 @@ impl<A: TaskAction + 'static> Handler<NextTask> for TaskManager<A> {
action,
ctx.address(),
self.console.clone(),
self.init_params.max_retry_count,
)
.start();

Expand Down
2 changes: 1 addition & 1 deletion typegraph/node/sdk/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const rpcCall = (() => {
})();

export interface DeployTarget {
base_url: string;
baseUrl: string;
auth: {
username: string;
password: string;
Expand Down
3 changes: 3 additions & 0 deletions typegraph/node/sdk/src/tg_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ArtifactUploader } from "./tg_artifact_upload.js";
import { TypegraphOutput } from "./typegraph.js";
import { wit_utils } from "./wit.js";
import { execRequest } from "./utils/func_utils.js";
import { log } from "./io.js";

export class BasicAuth {
constructor(
Expand Down Expand Up @@ -97,6 +98,8 @@ export async function tgDeploy(
params.typegraphPath,
);
await artifactUploader.uploadArtifacts();
} else {
log.debug("no artifacts to upload");
}

// deploy the typegraph
Expand Down
16 changes: 12 additions & 4 deletions typegraph/node/sdk/src/tg_manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Manager {
} catch (err: any) {
log.failure({
typegraph: this.#typegraph.name,
errors: err?.stack ?? [err?.message ?? "failed to serialize typegraph"],
errors: getErrorStack(err, "failed to serialize typegraph"),
});
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ export class Manager {
} catch (err: any) {
log.failure({
typegraph: this.#typegraph.name,
errors: err?.stack ?? [err?.message ?? "failed to serialize typegraph"],
errors: getErrorStack(err, "failed to serialize typegraph"),
});
return;
}
Expand All @@ -114,7 +114,7 @@ export class Manager {
const deployTarget = await rpc.getDeployTarget();
const { response } = await tgDeploy(reusableTgOutput, {
typegate: {
url: deployTarget.base_url,
url: deployTarget.baseUrl,
auth: new BasicAuth(
deployTarget.auth.username,
deployTarget.auth.password,
Expand All @@ -132,9 +132,17 @@ export class Manager {
} catch (err: any) {
log.failure({
typegraph: this.#typegraph.name,
errors: err?.stack ?? [err?.message ?? "failed to deploy typegraph"],
errors: getErrorStack(err, "failed to deploy typegraph"),
});
return;
}
}
}

function getErrorStack(err: any, defaultErr: string): string[] {
if (err instanceof Error) {
log.debug(err);
return [err.message];
}
return err?.stack ?? [err?.toString() ?? defaultErr];
}
2 changes: 1 addition & 1 deletion whiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ meta-cli:
- "typegate/src/**/*.ts"
- "typegate/core/**/*.rs"
- "libs/deno/**/*"
command: "cargo run -p meta-cli -- -C examples/typegraphs dev --run-destructive-migrations"
command: "cargo run -p meta-cli -- -C examples/typegraphs dev --run-destructive-migrations -vvv"
depends_on:
- typegraph

Expand Down

0 comments on commit 0890198

Please sign in to comment.