Skip to content

Commit

Permalink
use newest api publish API
Browse files Browse the repository at this point in the history
  • Loading branch information
fazo96 committed Oct 5, 2018
1 parent 8c07e16 commit 528a0ca
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/store/modules/data/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const CRAWLER_PROGRESS_POLL_INTERVAL = 5000 // ms
function getInitialState() {
return {
running: false,
savingToIPFS: false,
error: null
}
}
Expand Down Expand Up @@ -94,7 +93,7 @@ export function pollCrawlerProgress() {
let wasBackendCrawlingInProgress = false

do {
isBackendCrawlingInProgress = await readCrawlerProgress(didId)
isBackendCrawlingInProgress = hasInProgressJobs(await getCrawlerStatus(didId))

console.log('crawler running state: ' + isBackendCrawlingInProgress)

Expand All @@ -117,7 +116,14 @@ export function pollCrawlerProgress() {
}
}

async function readCrawlerProgress(didId) {
function hasInProgressJobs(crawlerStatus) {
for (const status of crawlerStatus.rows) {
if (status.status === 'CREATED' || status.status === 'RUNNING') return true
}
return false
}

async function getCrawlerStatus(didId) {
try {
const response = await fetch(`${API_URL}/api/v1/crawl/${didId}`, {
headers: {
Expand All @@ -128,10 +134,10 @@ async function readCrawlerProgress(didId) {

const responseJson = await response.json()
console.log(responseJson)
return responseJson.status === 'RUNNING'
return responseJson
} catch (err) {
console.error(err)
return false
return []
}
}

Expand Down

0 comments on commit 528a0ca

Please sign in to comment.