Closed kostysh closed 3 months ago
Thank you for the issue! I will solve these and give you an answer as soon as possible.
@kostysh This was fixed in v1.1.9 π
Use it like this!
interface ProcessJobData extends JobAttributesData {
myId: string;
}
pulse.define<ProcessJobData>(
'processJob',
async (job) => {
const { myId } = job.attrs.data;
// ...
},
{
concurrency: 3,
priority: 'normal',
}
);
Cool! Thanks!
Thank you, it works now. What is about a done
callback argument? In Agenda
it was possible to provide done
with an error for saving the finished job state as failed with a specific error.
Thank you, it works now. What is about a
done
callback argument? InAgenda
it was possible to providedone
with an error for saving the finished job state as failed with a specific error.
@kostysh
The done()
callback argument is just a void.
Is there an example code for the case you're talking about?
Maybe this is what you want?
pulse.define(
'send email report',
async (job, done) => {
const { to } = job.attrs.data;
console.log(`Sending email report to ${to}`);
// this!
try {
done();
} catch (error) {
console.log('error:', error);
}
},
{ lockLifetime: 5 * 1000, priority: 'high', concurrency: 10 }
);
Thank you, it works now. What is about a
done
callback argument? InAgenda
it was possible to providedone
with an error for saving the finished job state as failed with a specific error.@kostysh The
done()
callback argument is just a void. Is there an example code for the case you're talking about?
As I can see done
function should match the function const jobCallback = async (error?: Error, result?: unknown)
of https://github.com/pulsecron/pulse/blob/main/src/job/run.ts
as it is called here:
if (definition.fn.length === 2) {
debug('[%s:%s] process function being called', this.attrs.name, this.attrs._id);
await definition.fn(this, jobCallback); // <---- definition function with done callback param
} else {
debug('[%s:%s] process function being called', this.attrs.name, this.attrs._id);
const result = await definition.fn(this);
await jobCallback(undefined, result);
}
Processor definition should be something like:
export type Processor<T extends JobAttributesData> = (job: Job<T>, done?: (error?: Error, result?: unknown) => void) => unknown | Promise<unknown>;
Usage with done param:
pulse.define('sendEmail', async (job, done) => {
//....
if (error) {
done(new Error('Error message'));
return;
}
// if some result has to be returned:
done(undefined, 'Result data');
// else
done();
})
Usage without done param:
pulse.define('sendEmail', async (job) => {
//....
if (error) {
throw new Error('Error message')
}
// if some result has to be returned:
return 'Result data';
// else just return void
})
κ°μ¬ν©λλ€. μ΄μ μλν©λλ€. μ½λ°± μΈμ λ 무μμ λκΉ
done
? νΉμ μ€λ₯λ‘ μΈν΄ μλ£λ μμ μνλ₯Ό μ€ν¨λ‘ μ μ₯νλ λ° μ€λ₯λ₯ΌAgenda
μ 곡ν μ μμμ΅λλ€ .done
@kostyshμ½λ°±
done()
μΈμλ λ¨μ§ 무ν¨μ λλ€. λΉμ μ΄ λ§νλ μ¬λ‘μ λν μμ μ½λκ° μμ΅λκΉ?λ΄κ° λ³Ό μ μλ―μ΄ ν¨μλ https://github.com/pulsecron/pulse/blob/main/src/job/run.ts μ
done
ν¨μμ μΌμΉν΄μΌ ν©λλ€ .const jobCallback = async (error?: Error, result?: unknown)
μ¬κΈ°μμλ λ€μκ³Ό κ°μ΄ λΆλ¦ λλ€.
if (definition.fn.length === 2) { debug('[%s:%s] process function being called', this.attrs.name, this.attrs._id); await definition.fn(this, jobCallback); // <---- definition function with done callback param } else { debug('[%s:%s] process function being called', this.attrs.name, this.attrs._id); const result = await definition.fn(this); await jobCallback(undefined, result); }
νλ‘μΈμ μ μλ λ€μκ³Ό κ°μμΌ ν©λλ€.
export type Processor<T extends JobAttributesData> = (job: Job<T>, done?: (error?: Error, result?: unknown) => void) => unknown | Promise<unknown>;
done 맀κ°λ³μλ₯Ό μ¬μ©ν μ¬μ©λ²:
pulse.define('sendEmail', async (job, done) => { //.... if (error) { done(new Error('Error message')); return; } // if some result has to be returned: done(undefined, 'Result data'); // else done(); })
done 맀κ°λ³μκ° μλ μ¬μ©λ²:
pulse.define('sendEmail', async (job) => { //.... if (error) { throw new Error('Error message') } // if some result has to be returned: return 'Result data'; // else just return void })
Thank you for your dedication. @tiberioalunni @kostysh We released a new version reflecting your opinion > v1.1.11 π
Also we updated docs
I just tried
Pulse
and faced an issue with a job processor definition type. Here is a short example:The issue is, possibly, here: