@@ -222,3 +222,77 @@ test.group('JobDispatcher | DispatchResult', () => {
222222 assert . property ( result , 'jobId' )
223223 } )
224224} )
225+
226+ test . group ( 'JobDispatcher | groupId' , ( ) => {
227+ test ( 'should dispatch job with groupId' , async ( { assert } ) => {
228+ const sharedAdapter = memory ( ) ( )
229+
230+ const localConfig = {
231+ default : 'memory' ,
232+ adapters : { memory : ( ) => sharedAdapter } ,
233+ }
234+
235+ await QueueManager . init ( localConfig )
236+
237+ const dispatcher = new JobDispatcher ( 'NewsletterJob' , { userId : 1 } )
238+
239+ const { jobId } = await dispatcher . group ( 'newsletter-jan-2025' ) . run ( )
240+
241+ assert . isString ( jobId )
242+
243+ const job = await sharedAdapter . pop ( )
244+
245+ assert . isNotNull ( job )
246+ assert . equal ( job ! . id , jobId )
247+ assert . equal ( job ! . groupId , 'newsletter-jan-2025' )
248+ } )
249+
250+ test ( 'should dispatch multiple jobs with same groupId' , async ( { assert } ) => {
251+ const sharedAdapter = memory ( ) ( )
252+
253+ const localConfig = {
254+ default : 'memory' ,
255+ adapters : { memory : ( ) => sharedAdapter } ,
256+ }
257+
258+ await QueueManager . init ( localConfig )
259+
260+ const groupId = 'batch-export-123'
261+
262+ await new JobDispatcher ( 'ExportJob' , { userId : 1 } ) . group ( groupId ) . run ( )
263+ await new JobDispatcher ( 'ExportJob' , { userId : 2 } ) . group ( groupId ) . run ( )
264+ await new JobDispatcher ( 'ExportJob' , { userId : 3 } ) . group ( groupId ) . run ( )
265+
266+ const job1 = await sharedAdapter . pop ( )
267+ const job2 = await sharedAdapter . pop ( )
268+ const job3 = await sharedAdapter . pop ( )
269+
270+ assert . equal ( job1 ! . groupId , groupId )
271+ assert . equal ( job2 ! . groupId , groupId )
272+ assert . equal ( job3 ! . groupId , groupId )
273+ } )
274+
275+ test ( 'should work with other options like priority and queue' , async ( { assert } ) => {
276+ const sharedAdapter = memory ( ) ( )
277+
278+ const localConfig = {
279+ default : 'memory' ,
280+ adapters : { memory : ( ) => sharedAdapter } ,
281+ }
282+
283+ await QueueManager . init ( localConfig )
284+
285+ const { jobId } = await new JobDispatcher ( 'ImportJob' , { file : 'data.csv' } )
286+ . group ( 'import-batch-456' )
287+ . toQueue ( 'imports' )
288+ . priority ( 2 )
289+ . run ( )
290+
291+ const job = await sharedAdapter . popFrom ( 'imports' )
292+
293+ assert . isNotNull ( job )
294+ assert . equal ( job ! . id , jobId )
295+ assert . equal ( job ! . groupId , 'import-batch-456' )
296+ assert . equal ( job ! . priority , 2 )
297+ } )
298+ } )
0 commit comments