Skip to content

Commit 2f55440

Browse files
committed
Job examples
1 parent 487a9b2 commit 2f55440

File tree

8 files changed

+101
-34
lines changed

8 files changed

+101
-34
lines changed

examples/async.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
})();

examples/config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
})();

examples/deps.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
})();

examples/failed.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
})();

examples/fast.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
})();

examples/index.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/promise.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
})();

examples/timeout.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
})();

0 commit comments

Comments
 (0)