Use mtf-module-redis as submodule
This commit is contained in:
parent
b099a18170
commit
da60461d81
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "src/modules/redis"]
|
||||||
|
path = src/modules/redis
|
||||||
|
url = https://gitea.spilum.net/Spilum.Net/mtf-module-redis
|
||||||
@ -28,33 +28,7 @@ db.sequelize = sequelize;
|
|||||||
|
|
||||||
db.intent = require("./intent.model")(sequelize, Sequelize);
|
db.intent = require("./intent.model")(sequelize, Sequelize);
|
||||||
|
|
||||||
// Redis Connection
|
|
||||||
const Redis = require('redis');
|
|
||||||
const redis = {};
|
|
||||||
|
|
||||||
redis.client = Redis.createClient({
|
|
||||||
url: `redis://default@${redisConfig.REDIS_HOST}:${redisConfig.REDIS_PORT}`
|
|
||||||
});
|
|
||||||
|
|
||||||
redis.ensureGroup = async (stream, group) => {
|
|
||||||
await redis.client.connect().catch(console.error);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await redis.client.xGroupCreate(stream, group, "0", {MKSTREAM: true});
|
|
||||||
|
|
||||||
console.log(`Created consumer group: ${group} (${stream})`);
|
|
||||||
} catch (err) {
|
|
||||||
if (err.message.includes('BUSYGROUP')) {
|
|
||||||
console.log(`Consumer group already exists: ${group} (${stream})`);
|
|
||||||
} else {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await redis.client.quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
db,
|
db
|
||||||
redis
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
1
src/modules/redis
Submodule
1
src/modules/redis
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e41a75e7436a059ab963c5db7b62ca524cacc4e5
|
||||||
@ -7,10 +7,11 @@ const {env, pipeline} = require("@xenova/transformers");
|
|||||||
|
|
||||||
const models = require("./models");
|
const models = require("./models");
|
||||||
const db = models.db;
|
const db = models.db;
|
||||||
const redis = models.redis;
|
|
||||||
const {sequelize, Sequelize} = db;
|
const {sequelize, Sequelize} = db;
|
||||||
const Intent = db.intent;
|
const Intent = db.intent;
|
||||||
|
|
||||||
|
const {redis} = require('./modules/redis');
|
||||||
|
|
||||||
async function getIntents() {
|
async function getIntents() {
|
||||||
try {
|
try {
|
||||||
const intents = await Intent.findAll();
|
const intents = await Intent.findAll();
|
||||||
@ -116,8 +117,6 @@ async function handleIntent(streamKey, msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processor(group, consumer, streamKey) {
|
async function processor(group, consumer, streamKey) {
|
||||||
await redis.client.connect().catch(console.error);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const res = await redis.client.xReadGroup(
|
const res = await redis.client.xReadGroup(
|
||||||
group,
|
group,
|
||||||
@ -154,6 +153,7 @@ const main = async () => {
|
|||||||
|
|
||||||
await initModel();
|
await initModel();
|
||||||
|
|
||||||
|
await redis.connect();
|
||||||
await redis.ensureGroup("transcripts", 'nlp');
|
await redis.ensureGroup("transcripts", 'nlp');
|
||||||
await redis.ensureGroup("commands", 'nlp');
|
await redis.ensureGroup("commands", 'nlp');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user