Skip to content

Commit

Permalink
fix: keep job alive
Browse files Browse the repository at this point in the history
  • Loading branch information
just-paja committed Jun 8, 2023
1 parent abd4115 commit f342362
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/djorm-cloud-jobs/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { error, info } = require('djorm/logger')
const { getModel } = require('djorm/models')
const { getSettings, init, shutdown } = require('djorm/config')
const { getSettings, init, isUp, shutdown } = require('djorm/config')
const { parseMessage } = require('./pubsub')
const { registerEntrypoint } = require('./entry')
const { runTask } = require('./runTask')
Expand All @@ -16,7 +16,9 @@ const { RuntimeError } = require('./errors')
function createProcessWrapper (fn) {
return async function (job) {
try {
await init()
if (!isUp()) {
await init()
}
await fn(job)
} catch (processError) {
/* istanbul ignore next */
Expand All @@ -34,7 +36,7 @@ function createProcessWrapper (fn) {
} finally {
// Do not shutdown in test environment
const config = getSettings('cloudJobs', {})
if (!(config.local && !config.pool)) {
if (isUp() && (!config.keepAlive || !(config.local && !config.pool))) {
await shutdown()
}
}
Expand Down

0 comments on commit f342362

Please sign in to comment.