1
+ import { createMachine } from 'xstate' ;
2
+
3
+ /** If using VSCode, install the XState VSCode extension to get a
4
+ * "Open Inspector" link above each machine in your code that will
5
+ * visualize the machine. Otherwise, you can paste code into stately.ai/viz.
6
+ */
7
+
8
+ interface WorkspaceContext {
9
+ errorMessage ?: string
10
+ }
11
+
12
+ type WorkspaceEvent =
13
+ | { type : "START" }
14
+ | { type : "STOP" }
15
+ | { type : "REBUILD" }
16
+
17
+ export const workspaceModel = createMachine < WorkspaceContext , WorkspaceEvent > (
18
+ {
19
+ id : "workspaceV2Model" ,
20
+ initial : "off" ,
21
+ states : {
22
+ off : {
23
+ on : {
24
+ START : "starting"
25
+ }
26
+ } ,
27
+ starting : {
28
+ invoke : {
29
+ src : "buildWorkspace" ,
30
+ onDone : "running" ,
31
+ onError : "error" ,
32
+ } ,
33
+ } ,
34
+ running : {
35
+ on : {
36
+ STOP : "stopping" ,
37
+ REBUILD : "rebuilding"
38
+ }
39
+ } ,
40
+ stopping : {
41
+ invoke : {
42
+ src : "stopWorkspace" ,
43
+ onDone : "off" ,
44
+ onError : "error"
45
+ }
46
+ } ,
47
+ rebuilding : {
48
+ invoke : {
49
+ src : "stopAndStartWorkspace" ,
50
+ onDone : "running" ,
51
+ onError : "error"
52
+ }
53
+ } ,
54
+ error : {
55
+ entry : "saveErrorMessage" ,
56
+ } ,
57
+ } ,
58
+ } ,
59
+ )
60
+
61
+ export const provisionerModel = createMachine ( {
62
+ id : 'provisionerModel' ,
63
+ initial : 'starting' ,
64
+ context : {
65
+ automator : undefined ,
66
+ supportedProjects : [ ]
67
+ } ,
68
+ states : {
69
+ starting : {
70
+ on : {
71
+ PROVISION : 'provisioning' ,
72
+ PARSE : 'parsing'
73
+ }
74
+ } ,
75
+ provisioning : {
76
+ invoke : {
77
+ src : "provision" ,
78
+ onDone : 'off' ,
79
+ onError : 'off'
80
+ }
81
+ } ,
82
+ parsing : {
83
+ invoke : {
84
+ src : 'parse' ,
85
+ onDone : 'off' ,
86
+ onError : 'off'
87
+ }
88
+ } ,
89
+ off : {
90
+ type : 'final'
91
+ }
92
+ }
93
+ } )
94
+
95
+ export const provisionerDaemonModel = createMachine ( {
96
+ id : 'provisionerd' ,
97
+ initial : 'polling' ,
98
+ states : {
99
+ polling : {
100
+ on : {
101
+ JOB_HAS_PROVISIONER_REGISTERED : 'executing' ,
102
+ NO_JOB_READY : 'polling'
103
+ }
104
+ } ,
105
+ executing : {
106
+ invoke : {
107
+ id : 'callProvisionerWithParameters' ,
108
+ src : 'provisionerModel' ,
109
+ onDone : { target : 'polling' , actions : [ 'returnState' , 'parseProjectCode' ] } ,
110
+ onError : { target : 'polling' , actions : [ 'returnState' , 'markJobFailed' ] }
111
+ }
112
+ }
113
+ }
114
+ } , {
115
+ services : { provisionerModel }
116
+ } )
0 commit comments