Skip to content

Instantly share code, notes, and snippets.

@bokuo-okubo
Last active March 30, 2021 06:35
Show Gist options
  • Save bokuo-okubo/eab9b3945fc7be1b7b13c64eb067ef59 to your computer and use it in GitHub Desktop.
Save bokuo-okubo/eab9b3945fc7be1b7b13c64eb067ef59 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'training',
initial: 'uploadDataset',
states: {
uploadDataset: {
type: 'parallel',
on: {
GOTO_NEXT_STEP: {
target: 'checkJobStatus',
cond: 'isDatasetUploaded'
}
},
states: {
training: {
initial: 'none',
states: {
none: {
on: {
'DATASET_UPLOADED.TRAINING': 'completed'
// TODO: async jobを実行して、contextにdatasetId詰める?
}
},
completed: {
on: {
'DATASET_CLEAR.TRAINING': 'none'
// TODO: async jobを実行して、contextにdatasetId詰める?
}
}
}
}, // training
evaluation: {
initial: 'none',
states: {
none: {
on: {
'DATASET_UPLOADED.EVALUATION': 'completed'
}
},
completed: {
on: {
'DATASET_CLEAR.EVALUATION': 'none'
}
}
}
} // evaluation
} // states
}, // uploadDataset
// -------
checkJobStatus: {
initial: 'created',
type: 'compound',
on: {
GOTO_NEXT_STEP: {
target: 'checkJobResult',
cond: 'isJobStatusSuccess'
}
},
states: {
created: {
on: {
BACKEND_JOB_STARTED: 'progressing.started'
}
},
progressing: {
initial: 'started',
states: {
started: {
on: {
BACKEND_JOB_PROGRESSING: {
target: 'load_done',
cond: (ctx, ev, meta) => ev.job === 'load'
},
BACKEND_JOB_FAILED: {
// TODO: errorをcontextに突っ込む
target: '#training.checkJobStatus.failure'
}
}
},
load_done: {
on: {
BACKEND_JOB_PROGRESSING: {
target: 'validation_done',
cond: (ctx, ev, meta) => ev.job === 'validation'
},
// TODO: errorをcontextに突っ込む
BACKEND_JOB_FAILED: '#training.checkJobStatus.failure'
}
},
validation_done: {
on: {
BACKEND_JOB_PROGRESSING: {
target: 'training_done',
cond: (ctx, ev, meta) => ev.job === 'training'
},
// TODO: errorをcontextに突っ込む
BACKEND_JOB_FAILED: '#training.checkJobStatus.failure'
}
},
training_done: {
on: {
BACKEND_JOB_COMPLETED: '#training.checkJobStatus.success'
}
}
}
}, //progressing
success: {
type: 'final'
},
failure: {}
} // states
}, // checkJobStatus
checkJobResult: {}
} //states
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment