remove mark
This commit is contained in:
38
wxmsg/task/worker/index.ts
Normal file
38
wxmsg/task/worker/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Worker } from "bullmq";
|
||||
import { redis } from './redis.ts';
|
||||
|
||||
import { Wx } from "../../src/wx";
|
||||
|
||||
const worker = new Worker('wxmsg', async job => {
|
||||
const wx = new Wx({
|
||||
appId: process.env.WX_APPID || '',
|
||||
appSecret: process.env.WX_APPSECRET || '',
|
||||
redis: redis
|
||||
});
|
||||
if (job.name === 'analyzeUserMsg') {
|
||||
const { touser, msg } = job.data;
|
||||
const accessToken = await wx.getAccessToken();
|
||||
const sendData = {
|
||||
touser,
|
||||
msgtype: 'text',
|
||||
text: {
|
||||
content: 'Hello World' + new Date().toISOString(),
|
||||
},
|
||||
};
|
||||
await wx.sendUserMessage(sendData);
|
||||
} else {
|
||||
throw new Error(`Unknown job name: ${job.name}`);
|
||||
}
|
||||
}, {
|
||||
connection: redis
|
||||
});
|
||||
|
||||
worker.on('completed', (job) => {
|
||||
console.log(`Job ${job.id} has completed!`);
|
||||
});
|
||||
|
||||
worker.on('failed', (job, err) => {
|
||||
console.log(`Job ${job?.id} has failed with error ${err.message}`);
|
||||
});
|
||||
|
||||
console.log('Worker is running...');
|
||||
Reference in New Issue
Block a user