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) => {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useConfig } from '@kevisual/use-config';
|
||||
import { useContextKey } from "@kevisual/context";
|
||||
|
||||
export const config = useConfig()
|
||||
|
||||
// 首先从 process.env 读取环境变量
|
||||
const redisConfig = {
|
||||
host: process.env.REDIS_HOST || 'kevisual.cn',
|
||||
@@ -27,14 +26,14 @@ export const createRedisClient = (options = {}) => {
|
||||
});
|
||||
// 监听连接事件
|
||||
redis.on('connect', () => {
|
||||
console.log('Redis 连接成功');
|
||||
// console.log('Redis 连接成功');
|
||||
});
|
||||
|
||||
redis.on('error', (err) => {
|
||||
console.error('Redis 连接错误', err);
|
||||
// console.error('Redis 连接错误', err);
|
||||
});
|
||||
redis.on('ready', () => {
|
||||
console.log('Redis 已准备好处理请求');
|
||||
// console.log('Redis 已准备好处理请求');
|
||||
});
|
||||
return redis;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user