Skip to content

Commit 039257c

Browse files
authored
make sure we bill all cases (#1277)
1 parent 93740ac commit 039257c

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

src/components/c2d/compute_engine_docker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,14 @@ export class C2DEngineDocker extends C2DEngine {
361361
}
362362
}
363363

364-
// get all jobs that are in the settle status
365-
const jobs = await this.db.getJobs(
366-
envs,
367-
undefined,
368-
undefined,
364+
// get all jobs that needs to be paid
365+
const jobs = await this.db.getJobsByStatus(envs, [
366+
C2DStatusNumber.AlgorithmFailed,
367+
C2DStatusNumber.DiskQuotaExceeded,
368+
C2DStatusNumber.ResultsFetchFailed,
369+
C2DStatusNumber.ResultsUploadFailed,
369370
C2DStatusNumber.JobSettle
370-
)
371+
])
371372
CORE_LOGGER.info(`ClaimPayments: Got ${jobs.length} jobs to check`)
372373
if (jobs.length > 0) {
373374
const providerAddress = this.getKeyManager().getEthAddress()

src/components/database/C2DDatabase.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ export class C2DDatabase extends AbstractDatabase {
8989
return await this.provider.getJobs(environments, fromTimestamp, consumerAddrs, status)
9090
}
9191

92+
async getJobsByStatus(
93+
environments: string[],
94+
status: C2DStatusNumber[]
95+
): Promise<DBComputeJob[]> {
96+
return await this.provider.getJobsByStatus(environments, status)
97+
}
98+
9299
async updateImage(image: string): Promise<void> {
93100
return await this.provider.updateImage(image)
94101
}

src/components/database/sqliteCompute.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class SQLiteCompute implements ComputeDatabaseProvider {
439439
})
440440
}
441441

442-
getJobs(
442+
async getJobs(
443443
environments?: string[],
444444
fromTimestamp?: string,
445445
consumerAddrs?: string[],
@@ -476,7 +476,44 @@ export class SQLiteCompute implements ComputeDatabaseProvider {
476476
selectSQL += ` WHERE ${conditions.join(' AND ')}`
477477
}
478478
selectSQL += ` ORDER BY dateCreated DESC`
479+
return await this.doQuery(selectSQL, params, environments)
480+
}
481+
482+
async getJobsByStatus(
483+
environments: string[],
484+
status: C2DStatusNumber[]
485+
): Promise<DBComputeJob[]> {
486+
let selectSQL = `SELECT * FROM ${this.schema.name}`
487+
488+
// sqlite3 bindings accept both strings and numbers; `status` is a numeric enum.
489+
const params: Array<string | number> = []
490+
const conditions: string[] = []
491+
492+
if (environments && environments.length > 0) {
493+
const placeholders = environments.map(() => '?').join(',')
494+
conditions.push(`environment IN (${placeholders})`)
495+
params.push(...environments)
496+
}
497+
498+
if (status && status.length > 0) {
499+
const placeholders = status.map(() => '?').join(',')
500+
conditions.push(`status IN (${placeholders})`)
501+
params.push(...status)
502+
}
503+
504+
if (conditions.length > 0) {
505+
selectSQL += ` WHERE ${conditions.join(' AND ')}`
506+
}
507+
selectSQL += ` ORDER BY dateCreated DESC`
508+
509+
return await this.doQuery(selectSQL, params, environments)
510+
}
479511

512+
private doQuery(
513+
selectSQL: string,
514+
params: Array<string | number>,
515+
environments: string[]
516+
) {
480517
return new Promise<DBComputeJob[]>((resolve, reject) => {
481518
this.db.all(selectSQL, params, (err, rows: any[] | undefined) => {
482519
if (err) {

0 commit comments

Comments
 (0)