Feat/next packages (#2646)

* fix mac build

* wip

* chore: Update the effects to get rid of bad pattern

* chore: Some small changes

* wip

* fix: Health checks don't show during race

* fix: Restart working

---------

Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
Jade
2024-06-19 17:30:05 -06:00
committed by GitHub
parent da3720c7a9
commit 355452cdb3
7 changed files with 65 additions and 34 deletions

View File

@@ -123,9 +123,9 @@ export class SystemForStartOs implements System {
return this.abi.uninit({ effects, nextVersion })
}
case "/main/start": {
if (this.onTerm) await this.onTerm()
const started = async (onTerm: () => Promise<void>) => {
await effects.setMainStatus({ status: "running" })
if (this.onTerm) await this.onTerm()
this.onTerm = onTerm
}
const daemons = await (
@@ -135,10 +135,11 @@ export class SystemForStartOs implements System {
})
).build()
this.onTerm = daemons.term
return
}
case "/main/stop": {
await effects.setMainStatus({ status: "stopped" })
if (this.onTerm) await this.onTerm()
await effects.setMainStatus({ status: "stopped" })
delete this.onTerm
return duration(30, "s")
}
@@ -183,6 +184,7 @@ export class SystemForStartOs implements System {
return dependencyConfig.update(options.input as any) // TODO
}
}
return
}
throw new Error(`Method ${options.procedure} not implemented.`)
}

View File

@@ -485,7 +485,7 @@ impl Actor for ServiceActor {
let mut current = seed.persistent_container.state.subscribe();
loop {
let kinds = dbg!(current.borrow().kinds());
let kinds = current.borrow().kinds();
if let Err(e) = async {
let main_status = match (
@@ -493,6 +493,14 @@ impl Actor for ServiceActor {
kinds.desired_state,
kinds.running_status,
) {
(Some(TransitionKind::Restarting), StartStop::Stop, Some(_)) => {
seed.persistent_container.stop().await?;
MainStatus::Restarting
}
(Some(TransitionKind::Restarting), StartStop::Start, _) => {
seed.persistent_container.start().await?;
MainStatus::Restarting
}
(Some(TransitionKind::Restarting), _, _) => MainStatus::Restarting,
(Some(TransitionKind::Restoring), _, _) => MainStatus::Restoring,
(Some(TransitionKind::BackingUp), _, Some(status)) => {
@@ -523,6 +531,30 @@ impl Actor for ServiceActor {
.mutate(|d| {
if let Some(i) = d.as_public_mut().as_package_data_mut().as_idx_mut(&id)
{
let previous = i.as_status().as_main().de()?;
let previous_health = previous.health();
let previous_started = previous.started();
let mut main_status = main_status;
match &mut main_status {
&mut MainStatus::Running { ref mut health, .. }
| &mut MainStatus::BackingUp { ref mut health, .. } => {
*health = previous_health.unwrap_or(health).clone();
}
_ => (),
};
match &mut main_status {
MainStatus::Running {
ref mut started, ..
} => {
*started = previous_started.unwrap_or(*started);
}
MainStatus::BackingUp {
ref mut started, ..
} => {
*started = previous_started.map(Some).unwrap_or(*started);
}
_ => (),
};
i.as_status_mut().as_main_mut().ser(&main_status)?;
}
Ok(())

View File

@@ -936,7 +936,6 @@ async fn stopped(context: EffectContext, params: ParamsMaybePackageId) -> Result
Ok(json!(matches!(package, MainStatus::Stopped)))
}
async fn running(context: EffectContext, params: ParamsPackageId) -> Result<Value, Error> {
dbg!("Starting the running {params:?}");
let context = context.deref()?;
let peeked = context.seed.ctx.db.peek().await;
let package_id = params.package_id;
@@ -956,9 +955,7 @@ async fn restart(
WithProcedureId { procedure_id, .. }: WithProcedureId<Empty>,
) -> Result<(), Error> {
let context = context.deref()?;
dbg!("here");
context.restart(procedure_id).await?;
dbg!("here");
Ok(())
}
@@ -1032,12 +1029,11 @@ struct SetMainStatus {
status: SetMainStatusStatus,
}
async fn set_main_status(context: EffectContext, params: SetMainStatus) -> Result<Value, Error> {
dbg!(format!("Status for main will be is {params:?}"));
let context = context.deref()?;
match params.status {
SetMainStatusStatus::Running => context.seed.started(),
SetMainStatusStatus::Stopped => context.seed.stopped(),
SetMainStatusStatus::Starting => context.seed.stopped(),
SetMainStatusStatus::Starting => context.seed.started(),
}
Ok(Value::Null)
}

View File

@@ -25,7 +25,7 @@ dist: $(TS_FILES) package.json node_modules README.md LICENSE
cp LICENSE dist/LICENSE
touch dist
full-bundle: clean bundle
full-bundle: bundle
check:
npm run check
@@ -36,7 +36,7 @@ fmt: node_modules
node_modules: package.json
npm ci
publish: clean bundle package.json README.md LICENSE
publish: bundle package.json README.md LICENSE
cd dist && npm publish --access=public
link: bundle

View File

@@ -154,7 +154,7 @@ export class Daemons<Manifest extends SDKManifest, Ids extends string> {
this.healthDaemons.forEach((x) =>
x.addWatcher(() => this.updateMainHealth()),
)
return {
const built = {
term: async (options?: { signal?: Signals; timeout?: number }) => {
try {
await Promise.all(this.healthDaemons.map((x) => x.term(options)))
@@ -163,6 +163,8 @@ export class Daemons<Manifest extends SDKManifest, Ids extends string> {
}
},
}
this.started(() => built.term())
return built
}
private updateMainHealth() {

View File

@@ -132,14 +132,14 @@ export class HealthDaemon {
this.effects.setHealth({
result: status,
message: health.message,
id: display,
id: this.id,
name: display,
})
} else {
this.effects.setHealth({
result: health.status,
message: health.message || "",
id: display,
id: this.id,
name: display,
})
}

View File

@@ -27,12 +27,11 @@ export class Overlay {
}
for (const dirPart of shared) {
await fs.mkdir(`${rootfs}/${dirPart}`, { recursive: true })
await execFile("mount", [
"--rbind",
`/${dirPart}`,
`${rootfs}/${dirPart}`,
])
const from = `/${dirPart}`
const to = `${rootfs}/${dirPart}`
await fs.mkdir(from, { recursive: true })
await fs.mkdir(to, { recursive: true })
await execFile("mount", ["--rbind", from, to])
}
return new Overlay(effects, id, rootfs, guid)
@@ -48,22 +47,22 @@ export class Overlay {
? options.subpath
: `/${options.subpath}`
: "/"
await execFile("mount", [
"--bind",
`/media/startos/volumes/${options.id}${subpath}`,
path,
])
const from = `/media/startos/volumes/${options.id}${subpath}`
await fs.mkdir(from, { recursive: true })
await fs.mkdir(path, { recursive: true })
await await execFile("mount", ["--bind", from, path])
} else if (options.type === "assets") {
const subpath = options.subpath
? options.subpath.startsWith("/")
? options.subpath
: `/${options.subpath}`
: "/"
await execFile("mount", [
"--bind",
`/media/startos/assets/${options.id}${subpath}`,
path,
])
const from = `/media/startos/assets/${options.id}${subpath}`
await fs.mkdir(from, { recursive: true })
await fs.mkdir(path, { recursive: true })
await execFile("mount", ["--bind", from, path])
} else if (options.type === "pointer") {
await this.effects.mount({ location: path, target: options })
} else if (options.type === "backup") {
@@ -72,11 +71,11 @@ export class Overlay {
? options.subpath
: `/${options.subpath}`
: "/"
await execFile("mount", [
"--bind",
`/media/startos/backup${subpath}`,
path,
])
const from = `/media/startos/backup${subpath}`
await fs.mkdir(from, { recursive: true })
await fs.mkdir(path, { recursive: true })
await execFile("mount", ["--bind", from, path])
} else {
throw new Error(`unknown type ${(options as any).type}`)
}