Skip to content

Commit

Permalink
fix: typos + some clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-0acf4 committed Sep 23, 2024
1 parent ba5f59c commit f91d81d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 51 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion src/substantial/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ mod tests {
.unwrap();
assert_eq!(metadata.len(), 1);

// lease acuire
// lease acquire
let lease = backend.acquire_lease(run_id.clone(), 123).unwrap();
assert!(lease, "lease acquired");
let lease2 = backend.acquire_lease(run_id.clone(), 123).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/typegate/src/runtimes/substantial/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { RunId, WorkerManager } from "./workflow_worker_manager.ts";
const logger = getLogger();

const POLL_INTERVAL_SECONDS = 1;
const LEASE_LIFESPAN = 3;
const LEASE_LIFESPAN_SECONDS = 3;

export interface WorkflowDescription {
name: string;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class Agent {
async #tryAcquireNextRun() {
const activeRunIds = await Meta.substantial.agentActiveLeases({
backend: this.backend,
lease_seconds: LEASE_LIFESPAN,
lease_seconds: LEASE_LIFESPAN_SECONDS,
});

logger.info(`Active leases: ${activeRunIds.join(", ")}`);
Expand All @@ -143,7 +143,7 @@ export class Agent {

const acquired = await Meta.substantial.agentAcquireLease({
backend: this.backend,
lease_seconds: LEASE_LIFESPAN,
lease_seconds: LEASE_LIFESPAN_SECONDS,
run_id: next.run_id,
});

Expand Down Expand Up @@ -317,7 +317,7 @@ export class Agent {
logger.info(`Renew lease ${runId}`);
await Meta.substantial.agentRenewLease({
backend: this.backend,
lease_seconds: LEASE_LIFESPAN,
lease_seconds: LEASE_LIFESPAN_SECONDS,
run_id: runId,
});
}
Expand Down Expand Up @@ -368,7 +368,7 @@ export class Agent {
await Meta.substantial.agentRemoveLease({
backend: this.backend,
run_id: runId,
lease_seconds: LEASE_LIFESPAN,
lease_seconds: LEASE_LIFESPAN_SECONDS,
});
}

Expand Down
6 changes: 0 additions & 6 deletions src/typegate/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,3 @@ export function collectFieldNames(tg: TypeGraph, typeIdx: number) {

export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));

export function addSecondsToDate(date: Date, seconds: number) {
const ret = new Date(date.getTime());
ret.setSeconds(ret.getSeconds() + seconds);
return ret;
}
1 change: 1 addition & 0 deletions src/typegraph/core/src/runtimes/substantial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn substantial_operation(
// Note: this is per typegate node basis
// And If the downtime in between interrupts is not negligible this will output nothing
// as there are no active workers running
// This feature might be handy for debugging (e.g. long running workers on the typegate it is queried upon)
let out = t::struct_()
.prop("count", t::integer().build()?)
.prop("workflow", t::string().build()?)
Expand Down
63 changes: 27 additions & 36 deletions tests/runtimes/substantial/substantial_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,41 +149,32 @@ Meta.test(
// let's wait for a bit to make sure interrupts are doing their jobs
await sleep(5 * 1000);

await t.should(
`fire "confirmation" events for "${emails.join(", ")}"`,
async () => {
await gql`
mutation {
# will pass
one: send_confirmation(
run_id: $one_run_id
event: { payload: true }
)
# will throw
two: send_confirmation(
run_id: $two_run_id
event: { payload: false }
)
# will abort
three: abort_email_confirmation(run_id: $three_run_id)
}
`
.withVars({
one_run_id: runIds[0],
two_run_id: runIds[1],
three_run_id: runIds[2],
})
.expectData({
one: runIds[0],
two: runIds[1],
three: runIds[2],
})
.on(e);
}
);
await t.should(`fire events for "${emails.join(", ")}"`, async () => {
await gql`
mutation {
# will pass
one: send_confirmation(run_id: $one_run_id, event: { payload: true })
# will throw
two: send_confirmation(run_id: $two_run_id, event: { payload: false })
# will abort
three: abort_email_confirmation(run_id: $three_run_id)
}
`
.withVars({
one_run_id: runIds[0],
two_run_id: runIds[1],
three_run_id: runIds[2],
})
.expectData({
one: runIds[0],
two: runIds[1],
three: runIds[2],
})
.on(e);
});

// This is arbitrary, if ops are leaking that means it should be increased
// Noticing the fired event may take a few seconds depending on `substantial_relaunch_ms`
// Noticing the fired event may take a few seconds depending on the interrupt relaunch time and poll interval
// Once noticed the workflow will complete and the worker destroyed
await sleep(10 * 1000);

Expand Down Expand Up @@ -211,13 +202,13 @@ Meta.test(
assertEquals(
body?.data?.email_results?.ongoing?.count,
0,
"zero workflow currently running"
"0 workflow currently running"
);

assertEquals(
body?.data?.email_results?.completed?.count,
3,
"three workflow completed"
"3 workflows completed"
);

const localSorter = (a: any, b: any) =>
Expand Down Expand Up @@ -252,7 +243,7 @@ Meta.test(
assertEquals(
received.sort(localSorter),
expected.sort(localSorter),
"complete only two workflows as one was aborted"
"'complete' two workflows as one was aborted"
);
})
.on(e);
Expand Down

0 comments on commit f91d81d

Please sign in to comment.