@@ -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