Skip to content

Commit

Permalink
fix: Only update space once you've got a snapshot_count of >0
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskerr committed Apr 14, 2020
1 parent 0ee067a commit 01d9d31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/js/flows/ingestFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,28 @@ const trackProgress = (client, dispatch, clusterId) => {
dispatch(Spaces.setIngestProgress(clusterId, name, n))
}

async function updateSpaceDetails() {
dispatch(Spaces.setDetail(clusterId, await client.spaces.get(name)))
}

function toPercent(status): number {
if (status.packet_total_size === 0) return 1
else return status.packet_read_size / status.packet_total_size
}

setProgress(0)
for await (let {type, ...status} of stream) {
if (type === "PacketPostStatus") {
setProgress(toPercent(status))
dispatch(Spaces.setDetail(clusterId, await client.spaces.get(name)))
}
if (type === "LogPostStatus") {
dispatch(Spaces.setDetail(clusterId, await client.spaces.get(name)))
}
if (type === "TaskEnd" && status.error) {
throw errors.pcapIngest(status.error.error)
switch (type) {
case "PacketPostStatus":
setProgress(toPercent(status))
if (status.snapshot_count > 0) updateSpaceDetails()
break
case "LogPostStatus":
updateSpaceDetails()
break
case "TaskEnd":
if (status.error) throw errors.pcapIngest(status.error.error)
break
}
}
setProgress(1)
Expand Down
1 change: 1 addition & 0 deletions src/js/flows/ingestFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let mockClient = {
yield {type: "TaskStart"}
yield {
type: "PacketPostStatus",
snapshot_count: 1,
start_time: {sec: 0, ns: 0},
update_time: {sec: 1, ns: 1},
packet_total_size: 100,
Expand Down

0 comments on commit 01d9d31

Please sign in to comment.