Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Available variables:
- // - Machine
- // - interpret
- // - assign
- // - send
- // - sendParent
- // - spawn
- // - raise
- // - actions
- // - XState (all XState exports)
- const States = {
- idle: 'idle',
- creatingBatch: 'creatingBatch',
- integratingDeployRequests: 'integratingDeployRequests',
- building: 'building',
- reverting: 'reverting',
- deploying: 'deploying',
- finalizing: 'finalizing',
- canceling: 'canceling',
- restarting: 'restarting',
- setupBatch: 'setupBatch',
- createWorkspace: 'createWorkspace',
- fetchDeployRequests: 'fetchDeployRequests',
- successful: 'successful',
- failed: 'failed'
- };
- const Transitions = {
- FINALIZE_BATCH: 'finalizeBatch',
- REVERT_DEPLOY_REQUESTS: 'revertDeployRequests',
- START_BATCH: 'START_BATCH',
- DEPLOY_TO_PRODUCTION: 'deployToProduction'
- };
- const fetchMachine = Machine({
- id: 'fetch',
- initial: 'idle',
- context: {
- retries: 0
- },
- states: {
- idle: {
- entry: () => console.log(`Entered state idle in batchMachine`),
- on: {
- START_BATCH: {
- target: 'creatingBatch',
- actions: () => console.log('Batch FSM: Start batch triggered')
- }
- }
- },
- [States.creatingBatch]: {
- entry: () =>
- console.log(`Entered state createBranch in batchMachine`),
- invoke: {
- id: 'createBatchMachine',
- src: 'createBatchMachine',
- onDone: {
- target: 'integratingDeployRequests'
- }
- }
- },
- [States.integratingDeployRequests]: {
- entry: () =>
- console.log(
- `Entered state ${States.integratingDeployRequests} in batchMachine`
- ),
- invoke: {
- id: 'integrateDeployRequestsMachine',
- src: 'integrateDeployRequestsMachine',
- onDone: {
- target: 'building'
- }
- }
- },
- [States.building]: {
- entry: () =>
- console.log(`Entered state ${States.building} in batchMachine`),
- invoke: {
- id: `buildMachine`,
- src: 'buildMachine',
- onDone: {
- actions: [() => console.log('finished building')],
- target: 'deploying'
- }
- }
- },
- [States.reverting]: {
- entry: () =>
- console.log(`Entered state ${States.reverting} in batchMachine`),
- invoke: {
- id: 'revertMachine',
- src: 'revertMachine',
- onDone: 'building'
- }
- },
- [States.deploying]: {
- entry: () =>
- console.log(`Entered state ${States.deploying} in batchMachine`),
- invoke: {
- id: `deployMachine`,
- src: 'deployMachine',
- onDone: {
- actions: [() => console.log('finished Deploying')]
- }
- },
- on: {
- [Transitions.DEPLOY_TO_PRODUCTION]: {
- actions: send(Transitions.DEPLOY_TO_PRODUCTION, {to: 'deployMachine'})
- },
- [Transitions.FINALIZE_BATCH]: States.finalizing
- }
- },
- [States.finalizing]: {
- entry: () =>
- console.log(`Entered state ${States.finalizing} in batchMachine`),
- invoke: {
- id: `finalizeMachine`,
- src: 'finalizeMachine',
- onDone: {
- actions: () => console.log('finished Finalizing'),
- target: 'idle'
- }
- }
- },
- [States.canceling]: {
- entry: () =>
- console.log(`Entered state ${States.canceling} in batchMachine`),
- invoke: {
- id: 'cancelBatch',
- src: 'cancelBatch',
- onDone: 'idle'
- }
- },
- [States.restarting]: {
- entry: () =>
- console.log(`Entered state ${States.restarting} in batchMachine`),
- invoke: {
- id: 'restartBatch',
- src: 'restartBatch',
- onDone: 'creatingBatch'
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement