summaryrefslogtreecommitdiff
path: root/client/faceAnalysis/faceAnalysis.actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/faceAnalysis/faceAnalysis.actions.js')
-rw-r--r--client/faceAnalysis/faceAnalysis.actions.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/client/faceAnalysis/faceAnalysis.actions.js b/client/faceAnalysis/faceAnalysis.actions.js
index 860d3292..f8d8973f 100644
--- a/client/faceAnalysis/faceAnalysis.actions.js
+++ b/client/faceAnalysis/faceAnalysis.actions.js
@@ -16,17 +16,20 @@ export const publicUrl = {
// standard loading events
const loading = (tag, offset) => ({
+ ts: Date.now(),
type: types.faceAnalysis.loading,
tag,
offset
})
const loaded = (tag, data, offset = 0) => ({
+ ts: Date.now(),
type: types.faceAnalysis.loaded,
tag,
data,
offset
})
const polled = (data, offset = 0) => ({
+ ts: Date.now(),
type: types.faceAnalysis.poll,
data,
offset
@@ -52,13 +55,19 @@ let pollTimeout = null
export const poll = (payload, taskURL) => dispatch => {
clearTimeout(pollTimeout)
- console.log('polling...')
+ // console.log('polling...')
get(taskURL)
.then(data => {
- console.log('poll', data)
+ // console.log('poll', data)
dispatch(polled(data))
- if (data.state !== 'error' && data.state !== 'complete') {
- pollTimeout = setTimeout(() => poll(payload, taskURL), POLL_DELAY)
+ // console.log(data.state)
+ if (data.state === 'COMPLETE' || data.state === 'SUCCESS') {
+ console.log('complete!')
+ } else if (data.state === 'ERROR' || data.state === 'FAILURE') {
+ console.log('errorr!')
+ dispatch(error(data))
+ } else {
+ pollTimeout = setTimeout(() => poll(payload, taskURL)(dispatch), POLL_DELAY)
}
})
.catch(err => dispatch(error('result', err)))
@@ -71,8 +80,8 @@ export const upload = (payload, file) => dispatch => {
dispatch(loading(tag))
post(url.upload(), fd)
.then(data => {
- console.log('loaded!', tag, data)
- dispatch(loaded(tag, data))
+ // console.log('loaded!', tag, data)
+ dispatch(polled(tag, data))
const { result, taskURL } = data
if (result && taskURL) {
poll(payload, taskURL)(dispatch)