File tree Expand file tree Collapse file tree 8 files changed +101
-34
lines changed Expand file tree Collapse file tree 8 files changed +101
-34
lines changed Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ,
2+ { worker, createTask } = require ( '..' ) ( ) ,
3+ manobi = worker ( 'manobi' ) ;
4+
5+ const manobi = worker ( 'manobi' ) ;
6+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
7+ setTimeout ( ( ) => {
8+ done ( null , 'acabou' ) ;
9+ } , 3000 ) ;
10+ } ) ;
11+ ( async ( ) => {
12+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
13+ console . log ( res ) ;
14+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ;
2+ const dlay = require ( '../' ) ( { database : 'dlay_tasks' } ) ,
3+ { worker, createTask } = dlay ;
4+
5+ const manobi = worker ( 'manobi' ) ;
6+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
7+ //fast exec
8+ //done(null, {sucesso: 'muleque'});
9+
10+ // Async exec
11+ const deps = await ctx . deps ( ) ;
12+ console . log ( deps ) ;
13+ const res = await fetch ( 'https://dog.ceo/api/breeds/image/random' ) ;
14+ return res . json ( ) ;
15+ } ) ;
16+ ( async ( ) => {
17+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
18+ console . log ( res ) ;
19+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ,
2+ { worker, createTask } = require ( '..' ) ( ) ,
3+ manobi = worker ( 'manobi' ) ;
4+
5+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
6+ // Async exec
7+ const deps = await ctx . deps ( ) ;
8+ if ( deps . length ) {
9+ //do something
10+ done ( ) ;
11+ }
12+ } ) ;
13+
14+ ( async ( ) => {
15+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
16+ console . log ( res ) ;
17+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ,
2+ { worker, createTask } = require ( '..' ) ( ) ,
3+ manobi = worker ( 'manobi' ) ;
4+
5+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
6+ done ( { message : 'Something very wrong have happened' } ) ;
7+ } ) ;
8+
9+ ( async ( ) => {
10+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
11+ console . log ( res ) ;
12+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ,
2+ { worker, createTask } = require ( '..' ) ( ) ,
3+ manobi = worker ( 'manobi' ) ;
4+
5+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
6+ done ( null , { sucesso : 'muleque' } ) ;
7+ } ) ;
8+ ( async ( ) => {
9+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
10+ console . log ( res ) ;
11+ } ) ( ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ,
2+ { worker, createTask } = require ( '..' ) ( ) ,
3+ manobi = worker ( 'manobi' ) ;
4+
5+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
6+ // Async exec
7+ const res = await fetch ( 'https://dog.ceo/api/breeds/image/random' ) ;
8+ return res . json ( ) ;
9+ } ) ;
10+
11+ ( async ( ) => {
12+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
13+ console . log ( res ) ;
14+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const fetch = require ( 'node-fetch' ) ;
2+ const dlay = require ( '../' ) ( { database : 'dlay_tasks' } ) ,
3+ { worker, createTask } = dlay ;
4+
5+ const manobi = worker ( 'manobi' ) ;
6+ manobi . addJob ( 'compress' , async ( ctx , done ) => {
7+ // never calls done will reach the task timeout
8+ setTimeout ( ( ) => {
9+ console . log ( this . tasks ) ;
10+ } , 50000 ) ;
11+ } ) ;
12+ ( async ( ) => {
13+ const res = await createTask ( { date : new Date ( ) . toISOString ( ) } ) ;
14+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments