@@ -43,22 +43,25 @@ export async function printFile(doc) {
43
43
if ( randomP . status === 'idle' ) {
44
44
logger . info ( `Printing ${ _id } on ${ randomP . printer } ` ) ;
45
45
await print ( path . resolve ( process . cwd ( ) , `data/${ tid } #${ _id } .pdf` ) , randomP . printer , 1 , 5 ) ;
46
- return ;
46
+ return randomP . printer ;
47
47
}
48
48
for ( const printer of printers . filter ( ( p ) => p . printer !== randomP . printer ) ) {
49
49
logger . info ( `Checking ${ printer . printer } ${ printer . status } ` ) ;
50
50
if ( printer . status === 'idle' ) {
51
51
logger . info ( `Printing ${ _id } on ${ printer . printer } ` ) ;
52
52
await print ( path . resolve ( process . cwd ( ) , `data/${ tid } #${ _id } .pdf` ) , printer . printer , 1 , 5 ) ;
53
- return ;
53
+ return printer . printer ;
54
54
}
55
55
}
56
56
logger . info ( 'No Printer can found to print, sleeping...' ) ;
57
57
await sleep ( 3000 ) ;
58
58
}
59
59
}
60
+ logger . error ( 'No Printer Configured' ) ;
61
+ return null ;
60
62
} catch ( e ) {
61
63
logger . error ( e ) ;
64
+ return null ;
62
65
}
63
66
}
64
67
@@ -83,8 +86,9 @@ async function fetchTask(c) {
83
86
}
84
87
if ( body . doc ) {
85
88
logger . info ( `Print task ${ body . doc . tid } #${ body . doc . _id } ...` ) ;
86
- await printFile ( body . doc ) ;
87
- await post ( `${ c . server } /client/${ c . token } /doneprint/${ body . doc . _id } ` ) ;
89
+ const printer = await printFile ( body . doc ) ;
90
+ if ( ! printer ) throw new Error ( 'No Printer Configured' ) ;
91
+ await post ( `${ c . server } /client/${ c . token } /doneprint/${ body . doc . _id } ?printer=${ printer } ` ) ;
88
92
logger . info ( `Print task ${ body . doc . tid } #${ body . doc . _id } completed.` ) ;
89
93
} else {
90
94
logger . info ( 'No print task, sleeping...' ) ;
0 commit comments