Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Lint
  • Loading branch information
presleyp committed Jan 12, 2022
commit a1ea349de3861df3aa6de170673c391a88b15701
158 changes: 78 additions & 80 deletions provisionersdk/proto/xstate_models.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,114 @@
import { createMachine } from 'xstate';
import { createMachine } from "xstate"

/** If using VSCode, install the XState VSCode extension to get a
* "Open Inspector" link above each machine in your code that will
/** If using VSCode, install the XState VSCode extension to get a
* "Open Inspector" link above each machine in your code that will
* visualize the machine. Otherwise, you can paste code into stately.ai/viz.
*/

interface WorkspaceContext {
errorMessage?: string
}

type WorkspaceEvent =
| { type: "START" }
| { type: "STOP" }
| { type: "REBUILD" }
type WorkspaceEvent = { type: "START" } | { type: "STOP" } | { type: "REBUILD" }

export const workspaceModel = createMachine<WorkspaceContext, WorkspaceEvent>(
{
id: "workspaceV2Model",
initial: "off",
states: {
off: {
on: {
START: "starting"
}
},
starting: {
invoke: {
src: "buildWorkspace",
onDone: "running",
onError: "error",
},
export const workspaceModel = createMachine<WorkspaceContext, WorkspaceEvent>({
id: "workspaceV2Model",
initial: "off",
states: {
off: {
on: {
START: "starting",
},
running: {
on: {
STOP: "stopping",
REBUILD: "rebuilding"
}
},
starting: {
invoke: {
src: "buildWorkspace",
onDone: "running",
onError: "error",
},
stopping: {
invoke: {
src: "stopWorkspace",
onDone: "off",
onError: "error"
}
},
running: {
on: {
STOP: "stopping",
REBUILD: "rebuilding",
},
rebuilding: {
invoke: {
src: "stopAndStartWorkspace",
onDone: "running",
onError: "error"
}
},
stopping: {
invoke: {
src: "stopWorkspace",
onDone: "off",
onError: "error",
},
error: {
entry: "saveErrorMessage",
},
rebuilding: {
invoke: {
src: "stopAndStartWorkspace",
onDone: "running",
onError: "error",
},
},
error: {
entry: "saveErrorMessage",
},
},
)
})

export const provisionerModel = createMachine({
id: 'provisionerModel',
initial: 'starting',
id: "provisionerModel",
initial: "starting",
context: {
automator: undefined,
supportedProjects: []
supportedProjects: [],
},
states: {
starting: {
on: {
PROVISION: 'provisioning',
PARSE: 'parsing'
}
PROVISION: "provisioning",
PARSE: "parsing",
},
},
provisioning: {
invoke: {
src: "provision",
onDone: 'off',
onError: 'off'
}
onDone: "off",
onError: "off",
},
},
parsing: {
invoke: {
src: 'parse',
onDone: 'off',
onError: 'off'
}
src: "parse",
onDone: "off",
onError: "off",
},
},
off: {
type: 'final'
}
}
type: "final",
},
},
})

export const provisionerDaemonModel = createMachine({
id: 'provisionerd',
initial: 'polling',
states: {
polling: {
on: {
JOB_HAS_PROVISIONER_REGISTERED: 'executing',
NO_JOB_READY: 'polling'
}
export const provisionerDaemonModel = createMachine(
{
id: "provisionerd",
initial: "polling",
states: {
polling: {
on: {
JOB_HAS_PROVISIONER_REGISTERED: "executing",
NO_JOB_READY: "polling",
},
},
executing: {
invoke: {
id: "callProvisionerWithParameters",
src: "provisionerModel",
onDone: { target: "polling", actions: ["returnState", "parseProjectCode"] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What returnState does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not implemented since this is for diagramming purposes, but it represents the fact that when provisionerd calls a provisioner and the provisioner executes the code, the resulting state is returned.

onError: { target: "polling", actions: ["returnState", "markJobFailed"] },
},
},
},
executing: {
invoke: {
id: 'callProvisionerWithParameters',
src: 'provisionerModel',
onDone: {target: 'polling', actions: ['returnState', 'parseProjectCode']},
onError: {target: 'polling', actions: ['returnState', 'markJobFailed']}
}
}
}
}, {
services: { provisionerModel }
})
},
{
services: { provisionerModel },
},
)