@
xzg1993 任务队列,比如定时的抓取数据,定时的发送 Email 。自己实现的话,有非常多麻烦的点,比如失败重试,比如并发控制,比如队列运维。
Trigger 一个很爽的功能是,支持帮你生成回调 URL ,这样你需要 url callback 回调的请求,不需要单独写路由,具体可以看这个代码:
https://github.com/daimajia/huntscreens/blob/23659e3ea04b8d521590573e1f085537c18de834/jobs/ph.jobs.ts#L79```javascript
const result = await io.waitForRequest<ScreenshotResponse>(
`call-screenshotone-${payload.uuid}`,
async (url) => {
await fetch(`
https://api.screenshotone.com/take`, {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(getScreenshotOneParams(payload.url, payload.uuid, url)),
})
},
{
timeoutInSeconds: 300
}
);
if(result.store.location) {
await
io.logger.info('Screenshot successfully:', { payload });
await db.update(producthunt).set({webp: true}).where(eq(producthunt.uuid, payload.uuid));
}else{
await io.logger.error('got screenshot error', result);
}
return {
payload: payload,
result: result.store
};
```
官方文档在这里:
https://trigger.dev/docs/documentation/guides/task-library#waitforrequest