Skip to content

Commit

Permalink
Change success definition (#33)
Browse files Browse the repository at this point in the history
* success -> healthy

* remove `success`

* update test
  • Loading branch information
juliangruber authored Oct 9, 2023
1 parent e2fd10b commit 1445c4b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
18 changes: 9 additions & 9 deletions lib/activity-state.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/* global Zinnia */

// Create activity events when we go online or offline
// Create activity events when we become healthy or produce errors
export class ActivityState {
#ok = null
#healthy = null

onOutdatedClient () {
this.onError('SPARK is outdated. Please upgrade Filecoin Station to the latest version.')
}

onError (msg) {
if (this.#ok === null || this.#ok) {
this.#ok = false
if (this.#healthy === null || this.#healthy) {
this.#healthy = false
Zinnia.activity.error(msg ?? 'SPARK failed reporting retrieval')
}
}

onSuccess () {
if (this.#ok === null) {
this.#ok = true
onHealthy () {
if (this.#healthy === null) {
this.#healthy = true
Zinnia.activity.info('SPARK started reporting retrievals')
} else if (!this.#ok) {
this.#ok = true
} else if (!this.#healthy) {
this.#healthy = true
Zinnia.activity.info('SPARK retrieval reporting resumed')
}
}
Expand Down
6 changes: 2 additions & 4 deletions lib/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export default class Spark {
async nextRetrieval () {
const { id: retrievalId, ...retrieval } = await this.getRetrieval()

let success = false
const stats = {
timeout: false,
startAt: new Date(),
Expand All @@ -144,13 +143,12 @@ export default class Spark {
const url = `ipfs://${retrieval.cid}?${searchParams.toString()}`
try {
await this.fetchCAR(url, stats)
success = true
} catch (err) {
console.error(`Failed to fetch ${url}`)
console.error(err)
}

const measurementId = await this.submitMeasurement(retrieval, { success, ...stats })
const measurementId = await this.submitMeasurement(retrieval, { ...stats })
Zinnia.jobCompleted()
return measurementId
}
Expand All @@ -159,7 +157,7 @@ export default class Spark {
while (true) {
try {
await this.nextRetrieval()
this.#activity.onSuccess()
this.#activity.onHealthy()
} catch (err) {
if (err.statusCode === 400 && err.serverMessage === 'OUTDATED CLIENT') {
this.#activity.onOutdatedClient()
Expand Down
3 changes: 1 addition & 2 deletions test/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('submitRetrieval', async () => {
return { status: 200, ok: true, async json () { return { id: 123 } } }
}
const spark = new Spark({ fetch })
await spark.submitMeasurement({ cid: 'bafytest' }, { success: true })
await spark.submitMeasurement({ cid: 'bafytest' }, {})
assertEquals(requests, [
{
url: 'https://spark.fly.dev/measurements',
Expand All @@ -127,7 +127,6 @@ test('submitRetrieval', async () => {
sparkVersion: SPARK_VERSION,
zinniaVersion: Zinnia.versions.zinnia,
cid: 'bafytest',
success: true,
participantAddress: Zinnia.walletAddress
}),
headers: { 'Content-Type': 'application/json' }
Expand Down

0 comments on commit 1445c4b

Please sign in to comment.