Skip to content

Commit

Permalink
Resume run (#182)
Browse files Browse the repository at this point in the history
* log-server: add endpoint to get info about a run

* log-server: log sequences and resuming with Store

* log-api: run resuming

* log-server: run resuming endpoint

* log-client: logout

* fix code formatting

* react-experiment: remove useError

* react-experiment: remove logger management from Run

* log-api: update api

* log-server: update api

* runner: update interface

* log-client: support for resume

* run: remove init prop, add loading prop

* log-client: refactor resume in its own method

* log-server: fix tests, server app, and cli

These were broken after a39df7e, which changed the admin role to the host role

* log-server: updates

* log-server: fix migrate database

* log-server: fix store tests

* update deps

* react-experiment: support for resumeAfter prop

* log-server: fix extraneous blocked run start

* log-server: prevent resuming when a run is running

* log-client returns log after which to resume

* update deps and fix code style
  • Loading branch information
QuentinRoy authored Nov 21, 2023
1 parent 40e5b59 commit aed9788
Show file tree
Hide file tree
Showing 57 changed files with 5,267 additions and 4,054 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-gorillas-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': major
---

Clients now keep access to a run after having canceled or completed it. One must delete the session to remove a client's access to a run.
5 changes: 5 additions & 0 deletions .changeset/giant-eagles-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-client': minor
---

Log client logout
6 changes: 6 additions & 0 deletions .changeset/late-kangaroos-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lightmill/log-server': minor
'@lightmill/log-api': minor
---

Add endpoint to get run info
5 changes: 5 additions & 0 deletions .changeset/lemon-moles-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-client': minor
---

resumeRun returns the log after which the run has been resumed
6 changes: 6 additions & 0 deletions .changeset/long-games-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lightmill/log-server': minor
'@lightmill/log-api': minor
---

Add the ability to resume a running or canceled run.
5 changes: 5 additions & 0 deletions .changeset/proud-carrots-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/react-experiment': minor
---

Add resumeAfter Run prop
5 changes: 5 additions & 0 deletions .changeset/silly-points-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/runner': major
---

Update Runner interface.
5 changes: 5 additions & 0 deletions .changeset/tidy-taxis-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': patch
---

Prevent resuming a run when there is already another run running
5 changes: 5 additions & 0 deletions .changeset/weak-months-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': patch
---

Fix run start being blocked when there run in the session but they're all completed
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install --frozen-lockfile
- run: pnpm run -r build
- run: pnpm run build-all

test:
needs: ['build']
Expand Down Expand Up @@ -65,8 +65,8 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install --frozen-lockfile
- run: pnpm run -r build
- run: pnpm run -r test
- run: pnpm run build-all
- run: pnpm run test-all

lint:
runs-on: ubuntu-latest
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
"name": "lightmill",
"license": "MIT",
"type": "module",
"packageManager": "pnpm@7.27.0",
"packageManager": "pnpm@8.10.2",
"private": false,
"scripts": {
"lint": "eslint . && prettier --check .",
"build-all": "pnpm -r build",
"test-all": "pnpm -r test run",
"changeset": "changeset",
"release": "pnpm -r build && changeset publish"
},
"dependencies": {
"@changesets/cli": "^2.26.2",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "8.47.0",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "8.54.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.0",
"prettier": "3.0.2",
"typescript": "5.1.6"
"eslint-plugin-import": "2.29.0",
"prettier": "3.1.0",
"typescript": "5.3.2"
}
}
4 changes: 2 additions & 2 deletions packages/convert-touchstone/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@lightmill/convert-touchstone",
"packageManager": "[email protected]",
"version": "3.0.0-alpha.8",
"type": "module",
"description": "Converts touchstone XML exports to lightmill format.",
"packageManager": "[email protected]",
"exports": {
"default": "./dist/convert-touchstone.js",
"*": "./dist/*"
Expand All @@ -23,7 +23,7 @@
"@lightmill/static-design": "workspace:*",
"@types/sax": "^1.2.4",
"cross-env": "^7.0.3",
"typescript": "5.1.6",
"typescript": "5.2.2",
"vite": "^4.4.8",
"vitest": "^0.34.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/convert-touchstone/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"rootDir": "src",
"outDir": "dist"
},
"include": ["src/**/*.ts"]
"include": ["./src/**/*.ts"]
}
4 changes: 2 additions & 2 deletions packages/log-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"prepublish": "pnpm run build"
},
"devDependencies": {
"typescript": "5.1.6",
"typescript": "5.2.2",
"vite": "^4.4.8",
"vitest": "^0.34.1"
},
"dependencies": {
"@zodios/core": "^10.9.2",
"zod": "^3.21.4"
},
"packageManager": "pnpm@7.17.0"
"packageManager": "pnpm@8.10.2"
}
70 changes: 47 additions & 23 deletions packages/log-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ErrorResponse = z.object({
status: z.literal('error'),
message: z.string(),
});
const Role = z.enum(['admin', 'participant']);
const Role = z.enum(['host', 'participant']);
const LogParameter = z.object({
type: z.string(),
// Required because requests can arrive out of order.
Expand All @@ -42,7 +42,9 @@ export const api = makeApi([
],
response: OkResponse.extend({
role: Role,
runs: z.array(z.string()),
runs: z.array(
z.object({ runId: z.string(), experimentId: z.string() }).strict(),
),
}).strict(),
errors: [
{ status: 400, schema: ErrorResponse },
Expand All @@ -54,7 +56,7 @@ export const api = makeApi([
path: '/sessions/current',
response: OkResponse.extend({
runs: z.array(
z.object({ id: z.string(), experiment: z.string() }).strict(),
z.object({ runId: z.string(), experimentId: z.string() }).strict(),
),
role: Role,
}).strict(),
Expand All @@ -76,8 +78,8 @@ export const api = makeApi([
{
schema: z
.object({
id: z.string().optional(),
experiment: z.string().optional(),
runId: z.string().optional(),
experimentId: z.string().optional(),
})
.strict()
.optional(),
Expand All @@ -86,23 +88,42 @@ export const api = makeApi([
},
],
response: OkResponse.extend({
run: z.string(),
experiment: z.string(),
links: z
runId: z.string(),
experimentId: z.string(),
}).strict(),
errors: [{ status: 403, schema: ErrorResponse.strict() }],
},
{
method: 'get',
path: '/experiments/:experimentId/runs/:runId',
response: OkResponse.extend({
run: z
.object({
logs: z.string(),
run: z.string(),
runId: z.string(),
experimentId: z.string(),
status: z.union([
z.literal('completed'),
z.literal('canceled'),
z.literal('running'),
]),
logs: z.array(
z
.object({
type: z.string(),
count: z.number(),
pending: z.number(),
lastNumber: z.number(),
})
.strict(),
),
})
.strict(),
}).strict(),
errors: [
{ status: 403, schema: ErrorResponse.strict() },
{ status: 400, schema: ErrorResponse.strict() },
],
errors: [{ status: 403, schema: ErrorResponse.strict() }],
},
{
method: 'patch',
path: '/experiments/:experiment/runs/:run',
path: '/experiments/:experimentId/runs/:runId',
response: OkResponse.strict(),
errors: [
{ status: 404, schema: ErrorResponse.strict() },
Expand All @@ -111,19 +132,22 @@ export const api = makeApi([
],
parameters: [
{
schema: z
.object({
status: z.union([z.literal('completed'), z.literal('canceled')]),
})
.strict(),
schema: z.union([
z
.object({
status: z.union([z.literal('completed'), z.literal('canceled')]),
})
.strict(),
z.object({ resumeFrom: z.number() }).strict(),
]),
name: 'body',
type: 'Body',
},
],
},
{
method: 'post',
path: '/experiments/:experiment/runs/:run/logs',
path: '/experiments/:experimentId/runs/:runId/logs',
parameters: [
{
schema: z.union([
Expand All @@ -139,7 +163,7 @@ export const api = makeApi([
},
{
method: 'get',
path: '/experiments/:experiment/logs',
path: '/experiments/:experimentId/logs',
parameters: [
{
name: 'type',
Expand Down Expand Up @@ -175,7 +199,7 @@ export type Response<
export type Error<
M extends Method,
P extends ZodiosPathsByMethod<Api, M>,
Status extends number,
Status extends number = number,
> = ZodiosErrorByPath<Api, M, P, Status>;
export type ErrorStatus<
M extends Method,
Expand Down
2 changes: 1 addition & 1 deletion packages/log-api/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outDir": "dist",
"target": "es2020",
"lib": ["es2020"],
"module": "ES2020",
"module": "Node16",
"moduleResolution": "Node16",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/log-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
"module": "ES2020",
"module": "Node16",
"moduleResolution": "Node16",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
Expand Down
Loading

0 comments on commit aed9788

Please sign in to comment.