@nextastic/queue
Advanced tools
Comparing version 0.4.3 to 1.0.0
@@ -36,8 +36,10 @@ #!/usr/bin/env node | ||
var import_node_process = __toESM(require("process")); | ||
var import_config2 = require("@nextastic/config"); | ||
// src/get-queue.ts | ||
var import_config = require("@nextastic/config"); | ||
var import_bullmq = require("bullmq"); | ||
var import_ioredis = __toESM(require("ioredis")); | ||
var queues = {}; | ||
var getQueue = (name) => { | ||
var getQueue = async (name) => { | ||
const existingQueue = queues[name]; | ||
@@ -47,3 +49,3 @@ if (existingQueue) { | ||
} | ||
const connection = new import_ioredis.default(process.env.REDIS_HOST, { | ||
const connection = new import_ioredis.default(await import_config.config.get("redis.host"), { | ||
maxRetriesPerRequest: null | ||
@@ -66,14 +68,19 @@ }); | ||
// src/start-dashboard.ts | ||
function startDashboard(queues2) { | ||
async function startDashboard(queues2) { | ||
const serverAdapter = new import_express2.ExpressAdapter(); | ||
serverAdapter.setBasePath("/jobs"); | ||
const bullQueues = await Promise.all( | ||
queues2.map(async (queue) => new import_bullMQAdapter.BullMQAdapter(await getQueue(queue))) | ||
); | ||
(0, import_api.createBullBoard)({ | ||
queues: queues2.map((queue) => new import_bullMQAdapter.BullMQAdapter(getQueue(queue))), | ||
queues: bullQueues, | ||
serverAdapter | ||
}); | ||
const app = (0, import_express.default)(); | ||
const hasPassword = import_node_process.default.env.QUEUE_DASHBOARD_PASSWORD !== void 0; | ||
const username = await import_config2.config.get("queue.dashboardUsername"); | ||
const password = await import_config2.config.get("queue.dashboardPassword"); | ||
const hasPassword = password !== void 0; | ||
if (hasPassword) { | ||
const auth = (0, import_express_basic_auth.default)({ | ||
users: { admin: import_node_process.default.env.QUEUE_DASHBOARD_PASSWORD ?? "" }, | ||
users: { [username]: password }, | ||
challenge: true | ||
@@ -80,0 +87,0 @@ // Will show browser prompt |
@@ -8,7 +8,6 @@ "use strict"; | ||
const sync_queue_1 = require("./sync-queue"); | ||
const get_queue_config_1 = require("./get-queue-config"); | ||
const config_1 = require("@nextastic/config"); | ||
const dispatch = async (name, data, options = {}) => { | ||
const { queue = 'default', debounce, ...jobOptions } = options; | ||
const config = await (0, get_queue_config_1.getQueueConfig)(); | ||
if (config.driver === 'sync') { | ||
if ((await config_1.config.get('queue.driver')) === 'sync') { | ||
return sync_queue_1.syncQueue.add(name, data, jobOptions); | ||
@@ -30,4 +29,4 @@ } | ||
} | ||
return (0, get_queue_1.getQueue)(queue).add(name, data, jobOptions); | ||
return (await (0, get_queue_1.getQueue)(queue)).add(name, data, jobOptions); | ||
}; | ||
exports.dispatch = dispatch; |
import { Queue } from 'bullmq'; | ||
export declare const getQueue: (name: string) => Queue<any, any, string, any, any, string>; | ||
export declare const getQueue: (name: string) => Promise<Queue<any, any, string, any, any, string>>; |
@@ -7,6 +7,7 @@ "use strict"; | ||
exports.getQueue = void 0; | ||
const config_1 = require("@nextastic/config"); | ||
const bullmq_1 = require("bullmq"); | ||
const ioredis_1 = __importDefault(require("ioredis")); | ||
const queues = {}; | ||
const getQueue = (name) => { | ||
const getQueue = async (name) => { | ||
const existingQueue = queues[name]; | ||
@@ -16,3 +17,3 @@ if (existingQueue) { | ||
} | ||
const connection = new ioredis_1.default(process.env.REDIS_HOST, { | ||
const connection = new ioredis_1.default(await config_1.config.get('redis.host'), { | ||
maxRetriesPerRequest: null, | ||
@@ -19,0 +20,0 @@ }); |
export * from './create-job'; | ||
export * from './get-queue'; | ||
export * from './get-queue-config'; | ||
export * from './schedule-jobs'; | ||
export * from './types'; | ||
export * from './work'; |
@@ -19,5 +19,4 @@ "use strict"; | ||
__exportStar(require("./get-queue"), exports); | ||
__exportStar(require("./get-queue-config"), exports); | ||
__exportStar(require("./schedule-jobs"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./work"), exports); |
@@ -8,3 +8,3 @@ "use strict"; | ||
for (const queue of queues) { | ||
const queueInstance = (0, get_queue_1.getQueue)(queue.name); | ||
const queueInstance = await (0, get_queue_1.getQueue)(queue.name); | ||
const schedulers = await queueInstance.getJobSchedulers(); | ||
@@ -11,0 +11,0 @@ if (!schedulers) { |
@@ -1,1 +0,1 @@ | ||
export declare function startDashboard(queues: string[]): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>; | ||
export declare function startDashboard(queues: string[]): Promise<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>; |
@@ -13,8 +13,10 @@ "use strict"; | ||
const node_process_1 = __importDefault(require("node:process")); | ||
const config_1 = require("@nextastic/config"); | ||
const get_queue_1 = require("./get-queue"); | ||
function startDashboard(queues) { | ||
async function startDashboard(queues) { | ||
const serverAdapter = new express_2.ExpressAdapter(); | ||
serverAdapter.setBasePath('/jobs'); | ||
const bullQueues = await Promise.all(queues.map(async (queue) => new bullMQAdapter_1.BullMQAdapter(await (0, get_queue_1.getQueue)(queue)))); | ||
(0, api_1.createBullBoard)({ | ||
queues: queues.map((queue) => new bullMQAdapter_1.BullMQAdapter((0, get_queue_1.getQueue)(queue))), | ||
queues: bullQueues, | ||
serverAdapter: serverAdapter, | ||
@@ -24,7 +26,9 @@ }); | ||
// Apply auth middleware to all routes | ||
const hasPassword = node_process_1.default.env.QUEUE_DASHBOARD_PASSWORD !== undefined; | ||
const username = await config_1.config.get('queue.dashboardUsername'); | ||
const password = await config_1.config.get('queue.dashboardPassword'); | ||
const hasPassword = password !== undefined; | ||
if (hasPassword) { | ||
// Add auth to require password for access | ||
const auth = (0, express_basic_auth_1.default)({ | ||
users: { admin: node_process_1.default.env.QUEUE_DASHBOARD_PASSWORD ?? '' }, | ||
users: { [username]: password }, | ||
challenge: true, // Will show browser prompt | ||
@@ -31,0 +35,0 @@ }); |
@@ -11,11 +11,13 @@ "use strict"; | ||
const get_jobs_1 = require("./get-jobs"); | ||
const config_1 = require("@nextastic/config"); | ||
async function work(params) { | ||
const { queues, jobsDir } = params; | ||
const jobs = await (0, get_jobs_1.getJobs)(jobsDir); | ||
const logger = await (0, logger_1.getLogger)(); | ||
for (const queue of queues) { | ||
const connection = new ioredis_1.default(process.env.REDIS_HOST, { | ||
const connection = new ioredis_1.default(await config_1.config.get('redis.host'), { | ||
maxRetriesPerRequest: null, | ||
}); | ||
new bullmq_1.Worker(queue.name, async (job) => { | ||
logger_1.logger.debug(`got job: ${job.name}`, { | ||
logger.debug(`got job: ${job.name}`, { | ||
event: 'job.start', | ||
@@ -26,3 +28,3 @@ data: JSON.stringify(job.data), | ||
if (!definedJob) { | ||
logger_1.logger.debug(`Missing job handler" ${job.name}`, { | ||
logger.debug(`Missing job handler" ${job.name}`, { | ||
event: 'job.missing_handler', | ||
@@ -38,3 +40,3 @@ data: JSON.stringify(job.data), | ||
job.log(message); | ||
logger_1.logger.debug(message, { | ||
logger.debug(message, { | ||
event: 'job.log', | ||
@@ -46,3 +48,3 @@ job: job.name, | ||
}); // Ignore TS, as already type-safe when accessing hadnle | ||
logger_1.logger.debug(`Completed job: ${job.name}`, { | ||
logger.debug(`Completed job: ${job.name}`, { | ||
event: 'job.complete', | ||
@@ -56,3 +58,3 @@ data: JSON.stringify(job.data), | ||
if (error instanceof Error) { | ||
logger_1.logger.debug(`Failed job: ${job.name}`, { | ||
logger.debug(`Failed job: ${job.name}`, { | ||
event: 'job.failed', | ||
@@ -65,3 +67,3 @@ data: JSON.stringify(job.data), | ||
} | ||
logger_1.logger.debug(`Failed job: ${job.name}`, { | ||
logger.debug(`Failed job: ${job.name}`, { | ||
event: 'job.failed', | ||
@@ -76,5 +78,9 @@ data: JSON.stringify(job.data), | ||
concurrency: queue.concurrency, | ||
removeOnComplete: { count: 1000 }, | ||
removeOnFail: { count: 5000 }, | ||
lockDuration: 600000, // 10 mins job timeout. Increased as code-gen (writing code) takes a while. | ||
removeOnComplete: { | ||
count: await config_1.config.get('queue.maxCompletedJobs'), | ||
}, | ||
removeOnFail: { | ||
count: await config_1.config.get('queue.maxFailedJobs'), | ||
}, | ||
lockDuration: await config_1.config.get('queue.jobTimeoutMs'), | ||
}); | ||
@@ -81,0 +87,0 @@ // eslint-disable-next-line no-console |
{ | ||
"name": "@nextastic/queue", | ||
"version": "0.4.3", | ||
"version": "1.0.0", | ||
"description": "Queue provides an API to run background jobs for your application.", | ||
@@ -48,6 +48,7 @@ "repository": { | ||
"minimist": "^1.2.8", | ||
"@nextastic/cache": "0.0.3", | ||
"@nextastic/logger": "0.1.0", | ||
"@nextastic/cache": "0.1.0", | ||
"@nextastic/logger": "1.0.0", | ||
"@nextastic/redis": "0.0.3", | ||
"@nextastic/utils": "0.0.1" | ||
"@nextastic/utils": "0.0.1", | ||
"@nextastic/config": "1.0.0" | ||
}, | ||
@@ -54,0 +55,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26912
1
0
12
28
+ Added@nextastic/config@1.0.0
+ Added@nextastic/cache@0.1.0(transitive)
+ Added@nextastic/config@1.0.0(transitive)
+ Added@nextastic/logger@1.0.0(transitive)
+ Addedbullmq@5.28.1(transitive)
- Removed@nextastic/cache@0.0.3(transitive)
- Removed@nextastic/logger@0.1.0(transitive)
- Removedbullmq@5.29.1(transitive)
Updated@nextastic/cache@0.1.0
Updated@nextastic/logger@1.0.0