SHARE
TWEET

Untitled

a guest Aug 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Available variables:
  2.   // - Machine
  3.   // - interpret
  4.   // - assign
  5.   // - send
  6.   // - sendParent
  7.   // - spawn
  8.   // - raise
  9.   // - actions
  10.   // - XState (all XState exports)
  11.  
  12.   const States = {
  13.   idle: 'idle',
  14.   creatingBatch: 'creatingBatch',
  15.   integratingDeployRequests: 'integratingDeployRequests',
  16.   building: 'building',
  17.   reverting: 'reverting',
  18.   deploying: 'deploying',
  19.   finalizing: 'finalizing',
  20.   canceling: 'canceling',
  21.   restarting: 'restarting',
  22.   setupBatch: 'setupBatch',
  23.   createWorkspace: 'createWorkspace',
  24.   fetchDeployRequests: 'fetchDeployRequests',
  25.   successful: 'successful',
  26.   failed: 'failed'
  27. };
  28.  
  29. const Transitions = {
  30.   FINALIZE_BATCH: 'finalizeBatch',
  31.   REVERT_DEPLOY_REQUESTS: 'revertDeployRequests',
  32.   START_BATCH: 'START_BATCH',
  33.   DEPLOY_TO_PRODUCTION: 'deployToProduction'
  34. };
  35.  
  36.  
  37.   const fetchMachine = Machine({
  38.     id: 'fetch',
  39.     initial: 'idle',
  40.     context: {
  41.       retries: 0
  42.     },
  43.     states: {
  44.     idle: {
  45.       entry: () => console.log(`Entered state idle in batchMachine`),
  46.       on: {
  47.         START_BATCH: {
  48.           target: 'creatingBatch',
  49.           actions: () => console.log('Batch FSM: Start batch triggered')
  50.         }
  51.       }
  52.     },
  53.     [States.creatingBatch]: {
  54.       entry: () =>
  55.         console.log(`Entered state createBranch in batchMachine`),
  56.       invoke: {
  57.         id: 'createBatchMachine',
  58.         src: 'createBatchMachine',
  59.         onDone: {
  60.           target: 'integratingDeployRequests'
  61.         }
  62.       }
  63.     },
  64.     [States.integratingDeployRequests]: {
  65.       entry: () =>
  66.         console.log(
  67.           `Entered state ${States.integratingDeployRequests} in batchMachine`
  68.         ),
  69.       invoke: {
  70.         id: 'integrateDeployRequestsMachine',
  71.         src: 'integrateDeployRequestsMachine',
  72.         onDone: {
  73.           target: 'building'
  74.         }
  75.       }
  76.     },
  77.     [States.building]: {
  78.       entry: () =>
  79.         console.log(`Entered state ${States.building} in batchMachine`),
  80.       invoke: {
  81.         id: `buildMachine`,
  82.         src: 'buildMachine',
  83.         onDone: {
  84.           actions: [() => console.log('finished building')],
  85.           target: 'deploying'
  86.         }
  87.       }
  88.     },
  89.     [States.reverting]: {
  90.       entry: () =>
  91.         console.log(`Entered state ${States.reverting} in batchMachine`),
  92.       invoke: {
  93.         id: 'revertMachine',
  94.         src: 'revertMachine',
  95.         onDone: 'building'
  96.       }
  97.     },
  98.     [States.deploying]: {
  99.       entry: () =>
  100.         console.log(`Entered state ${States.deploying} in batchMachine`),
  101.       invoke: {
  102.         id: `deployMachine`,
  103.         src: 'deployMachine',
  104.         onDone: {
  105.           actions: [() => console.log('finished Deploying')]
  106.         }
  107.       },
  108.       on: {
  109.         [Transitions.DEPLOY_TO_PRODUCTION]: {
  110.           actions: send(Transitions.DEPLOY_TO_PRODUCTION, {to: 'deployMachine'})
  111.         },
  112.         [Transitions.FINALIZE_BATCH]: States.finalizing
  113.       }
  114.     },
  115.     [States.finalizing]: {
  116.       entry: () =>
  117.         console.log(`Entered state ${States.finalizing} in batchMachine`),
  118.       invoke: {
  119.         id: `finalizeMachine`,
  120.         src: 'finalizeMachine',
  121.         onDone: {
  122.           actions: () => console.log('finished Finalizing'),
  123.           target: 'idle'
  124.         }
  125.       }
  126.     },
  127.     [States.canceling]: {
  128.       entry: () =>
  129.         console.log(`Entered state ${States.canceling} in batchMachine`),
  130.       invoke: {
  131.         id: 'cancelBatch',
  132.         src: 'cancelBatch',
  133.         onDone: 'idle'
  134.       }
  135.     },
  136.     [States.restarting]: {
  137.       entry: () =>
  138.         console.log(`Entered state ${States.restarting} in batchMachine`),
  139.       invoke: {
  140.         id: 'restartBatch',
  141.         src: 'restartBatch',
  142.         onDone: 'creatingBatch'
  143.       }
  144.     }
  145.   }
  146.   });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top