@@ -2,6 +2,7 @@ import { Queue } from 'bullmq';
2
2
import ving from '#ving/index.mjs' ;
3
3
import { useRedis } from '#ving/redis.mjs' ;
4
4
import { jobHandlers } from '#ving/jobs/map.mjs' ;
5
+ import { isObject } from '#ving/utils/identify.mjs' ;
5
6
6
7
/**
7
8
* Get BullMQ queue object.
@@ -35,7 +36,7 @@ export const getHandlerNames = () => {
35
36
* Enqueues a job in the jobs system.
36
37
*
37
38
* @param {string } type Must match the filename (without the `.mjs`) of a job handler.
38
- * @param {Object } data An object containing whatever data you wish to pass into the job.
39
+ * @param {Object|Undefined } data An object containing whatever data you wish to pass into the job.
39
40
* @param {Object } options An object with optional properties.
40
41
* @param {string } options.queueName The name of the queue to add this job to. Defaults to `jobs`.
41
42
* @param {number } options.delay The number of milliseconds to wait before executing this job. Defaults to running as soon as possible.
@@ -49,6 +50,9 @@ export const getHandlerNames = () => {
49
50
export const addJob = async ( type , data = { } , options = { queueName : 'jobs' } ) => {
50
51
if ( ! ( getHandlerNames ( ) . includes ( type ) ) )
51
52
throw ving . ouch ( 404 , `Job handler ${ type } is not available.` ) ;
53
+ if ( ! isObject ( data ) ) {
54
+ throw ving . ouch ( 442 , `Data must be an object.` ) ;
55
+ }
52
56
const queue = getQueue ( options ) ;
53
57
const jobOptions = {
54
58
removeOnComplete : {
0 commit comments