Skip to content

Commit 1f81668

Browse files
authored
feat: update get jobs handler to allow query for running jobs only (#1299)
* feat: update get jobs handler to allow query for running jobs only * fix: lint
1 parent 3c6906d commit 1f81668

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/@types/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,5 @@ export interface GetJobsCommand extends Command {
312312
environments?: string[]
313313
fromTimestamp?: string
314314
consumerAddrs?: string[]
315+
runningJobs?: boolean
315316
}

src/components/core/handler/getJobs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export class GetJobsHandler extends CommandHandler {
3030
const jobs = await c2d.getJobs(
3131
task.environments,
3232
task.fromTimestamp,
33-
task.consumerAddrs
33+
task.consumerAddrs,
34+
undefined,
35+
task.runningJobs
3436
)
3537
const sanitizedJobs = jobs.map((job) => {
3638
if (job.algorithm) {

src/components/database/C2DDatabase.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ export class C2DDatabase extends AbstractDatabase {
8484
environments?: string[],
8585
fromTimestamp?: string,
8686
consumerAddrs?: string[],
87-
status?: C2DStatusNumber
87+
status?: C2DStatusNumber,
88+
runningJobs?: boolean
8889
): Promise<DBComputeJob[]> {
89-
return await this.provider.getJobs(environments, fromTimestamp, consumerAddrs, status)
90+
return await this.provider.getJobs(
91+
environments,
92+
fromTimestamp,
93+
consumerAddrs,
94+
status,
95+
runningJobs
96+
)
9097
}
9198

9299
async getJobsByStatus(

src/components/database/sqliteCompute.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ export class SQLiteCompute implements ComputeDatabaseProvider {
447447
environments?: string[],
448448
fromTimestamp?: string,
449449
consumerAddrs?: string[],
450-
status?: C2DStatusNumber
450+
status?: C2DStatusNumber,
451+
runningJobs?: boolean
451452
): Promise<DBComputeJob[]> {
452453
let selectSQL = `SELECT * FROM ${this.schema.name}`
453454

@@ -460,9 +461,22 @@ export class SQLiteCompute implements ComputeDatabaseProvider {
460461
params.push(...environments)
461462
}
462463

463-
if (fromTimestamp) {
464-
conditions.push(`dateFinished >= ?`)
465-
params.push(fromTimestamp)
464+
if (runningJobs) {
465+
conditions.push(`status = ?`)
466+
params.push(C2DStatusNumber.RunningAlgorithm.toString())
467+
if (fromTimestamp) {
468+
conditions.push(`dateCreated >= ?`)
469+
params.push(fromTimestamp)
470+
}
471+
} else {
472+
if (fromTimestamp) {
473+
conditions.push(`dateFinished >= ?`)
474+
params.push(fromTimestamp)
475+
}
476+
if (status) {
477+
conditions.push(`status = ?`)
478+
params.push(status.toString())
479+
}
466480
}
467481

468482
if (consumerAddrs && consumerAddrs.length > 0) {
@@ -471,11 +485,6 @@ export class SQLiteCompute implements ComputeDatabaseProvider {
471485
params.push(...consumerAddrs)
472486
}
473487

474-
if (status) {
475-
conditions.push(`status = ?`)
476-
params.push(status.toString())
477-
}
478-
479488
if (conditions.length > 0) {
480489
selectSQL += ` WHERE ${conditions.join(' AND ')}`
481490
}

0 commit comments

Comments
 (0)