temp
This commit is contained in:
@@ -1,30 +1,31 @@
|
||||
import { Worker } from "bullmq";
|
||||
import { redis } from './redis.ts';
|
||||
import { redis, config } from './redis.ts';
|
||||
|
||||
import { Wx } from "../../src/wx";
|
||||
|
||||
|
||||
const worker = new Worker('wxmsg', async job => {
|
||||
const url = 'http://localhost:3005/api/router';
|
||||
const wx = new Wx({
|
||||
appId: process.env.WX_APPID || '',
|
||||
appSecret: process.env.WX_APPSECRET || '',
|
||||
redis: redis
|
||||
appId: config.WX_MP_APP_ID, appSecret: config.WX_MP_APP_SECRET,
|
||||
redis: redis,
|
||||
url,
|
||||
});
|
||||
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);
|
||||
await wx.postCenter(job.data);
|
||||
} else {
|
||||
throw new Error(`Unknown job name: ${job.name}`);
|
||||
}
|
||||
}, {
|
||||
connection: redis
|
||||
connection: redis,
|
||||
removeOnComplete: {
|
||||
age: 3600, // 1 hour
|
||||
count: 5000, // keep last 5000 jobs
|
||||
},
|
||||
removeOnFail: {
|
||||
age: 7200, // 2 hours
|
||||
count: 5000, // keep last 5000 jobs
|
||||
},
|
||||
});
|
||||
|
||||
worker.on('completed', (job) => {
|
||||
|
||||
Reference in New Issue
Block a user