1- var kue = require ( '../' )
2- , express = require ( 'express' ) ;
1+ var kue = require ( '../' )
2+ , express = require ( 'express' ) ;
33
44// create our job queue
55
@@ -15,51 +15,51 @@ var jobs = kue.createQueue()
1515
1616function create ( ) {
1717 var name = [ 'tobi' , 'loki' , 'jane' , 'manny' ] [ Math . random ( ) * 4 | 0 ] ;
18- console . log ( '- creating job for %s' , name ) ;
19- jobs . create ( 'video conversion' , {
18+ console . log ( '- creating job for %s' , name ) ;
19+ jobs . create ( 'video conversion' , {
2020 title : 'converting ' + name + '\'s to avi' , user : 1 , frames : 200
21- } ) . save ( ) ;
22- setTimeout ( create , Math . random ( ) * 3000 | 0 ) ;
21+ } ) . save ( ) ;
22+ setTimeout ( create , Math . random ( ) * 3000 | 0 ) ;
2323}
2424
2525create ( ) ;
2626
2727// process video conversion jobs, 3 at a time.
2828
29- jobs . process ( 'video conversion' , 3 , function ( job , done ) {
29+ jobs . process ( 'video conversion' , 3 , function ( job , done ) {
3030 var frames = job . data . frames ;
31- console . log ( "job process %d" , job . id ) ;
31+ console . log ( "job process %d" , job . id ) ;
3232 function next ( i ) {
3333 // pretend we are doing some work
34- convertFrame ( i , function ( err ) {
35- if ( err ) return done ( err ) ;
34+ convertFrame ( i , function ( err ) {
35+ if ( err ) return done ( err ) ;
3636 // report progress, i/frames complete
37- job . progress ( i , frames ) ;
38- if ( i == frames ) done ( )
39- else next ( i + 5 ) ;
40- } ) ;
37+ job . progress ( i , frames ) ;
38+ if ( i == frames ) done ( )
39+ else next ( i + 5 ) ;
40+ } ) ;
4141 }
4242
43- next ( 0 ) ;
44- } ) ;
43+ next ( 0 ) ;
44+ } ) ;
4545
4646function convertFrame ( i , fn ) {
47- setTimeout ( fn , Math . random ( ) * 100 ) ;
47+ setTimeout ( fn , Math . random ( ) * 100 ) ;
4848}
4949
5050// remove stale jobs
51- jobs . on ( 'job complete' , function ( id ) {
52- Job . get ( id , function ( err , job ) {
53- if ( err ) return ;
54- job . remove ( function ( err ) {
55- if ( err ) throw err ;
56- console . log ( 'removed completed job #%d' , job . id ) ;
57- } ) ;
58- } ) ;
59- } ) ;
51+ jobs . on ( 'job complete' , function ( id ) {
52+ Job . get ( id , function ( err , job ) {
53+ if ( err ) return ;
54+ job . remove ( function ( err ) {
55+ if ( err ) throw err ;
56+ console . log ( 'removed completed job #%d' , job . id ) ;
57+ } ) ;
58+ } ) ;
59+ } ) ;
6060
6161// start the UI
6262var app = express . createServer ( ) ;
63- app . use ( kue . app ) ;
64- app . listen ( 3000 ) ;
65- console . log ( 'UI started on port 3000' ) ;
63+ app . use ( kue . app ) ;
64+ app . listen ( 3000 ) ;
65+ console . log ( 'UI started on port 3000' ) ;
0 commit comments