Skip to content

Commit 4304edb

Browse files
committed
dry
1 parent bb47b99 commit 4304edb

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/boss.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,11 @@ class Boss extends EventEmitter implements types.EventsMixin {
8383
}
8484
}
8585

86-
async #executeSql (sql: string) {
87-
const started = Date.now()
88-
89-
const result = unwrapSQLResult(await this.#db.executeSql(sql))
90-
91-
const elapsed = (Date.now() - started) / 1000
92-
93-
if (
94-
elapsed > WARNINGS.SLOW_QUERY.seconds ||
95-
this.#config.__test__warn_slow_query
96-
) {
97-
await emitAndPersistWarning(this.#warningContext,
98-
WARNING_TYPES.SLOW_QUERY,
99-
WARNINGS.SLOW_QUERY.message,
100-
{ elapsed, sql }
101-
)
86+
async #executeQuery (query: plans.SqlQuery | string) {
87+
if (typeof (query) === 'string') {
88+
query = { text: query, values: [] }
10289
}
10390

104-
return result
105-
}
106-
107-
async #executeQuery (query: plans.SqlQuery) {
10891
const started = Date.now()
10992

11093
const result = unwrapSQLResult(await this.#db.executeSql(query.text, query.values))
@@ -150,7 +133,7 @@ class Boss extends EventEmitter implements types.EventsMixin {
150133
}
151134

152135
const sql = plans.deleteOldWarnings(this.#config.schema, this.#config.warningRetentionDays)
153-
await this.#executeSql(sql)
136+
await this.#executeQuery(sql)
154137
}
155138

156139
async supervise (value?: string | types.QueueResult[]) {
@@ -204,7 +187,7 @@ class Boss extends EventEmitter implements types.EventsMixin {
204187
const queues = rows.map((q) => q.name)
205188

206189
const cacheStatsSql = plans.cacheQueueStats(this.#config.schema, table, queues)
207-
const { rows: rowsCacheStats } = await this.#executeSql(cacheStatsSql)
190+
const { rows: rowsCacheStats } = await this.#executeQuery(cacheStatsSql)
208191

209192
if (this.#stopping) return
210193

@@ -219,7 +202,7 @@ class Boss extends EventEmitter implements types.EventsMixin {
219202
}
220203

221204
const sql = plans.failJobsByTimeout(this.#config.schema, table, queues)
222-
await this.#executeSql(sql)
205+
await this.#executeQuery(sql)
223206
}
224207
}
225208

@@ -238,7 +221,7 @@ class Boss extends EventEmitter implements types.EventsMixin {
238221
if (rows.length) {
239222
const queues = rows.map((q) => q.name)
240223
const sql = plans.deletion(this.#config.schema, table, queues)
241-
await this.#executeSql(sql)
224+
await this.#executeQuery(sql)
242225
}
243226
}
244227
}

0 commit comments

Comments
 (0)