Added REDIS_URL to .env.example and use this in queuManager, removed & commented debug code
This commit is contained in:
parent
fd8cefd0db
commit
66cbdec5b6
@ -2,6 +2,7 @@
|
|||||||
ENV=development
|
ENV=development
|
||||||
PORT=4000
|
PORT=4000
|
||||||
DATABASE_URL="mysql://root@localhost:3306/nq"
|
DATABASE_URL="mysql://root@localhost:3306/nq"
|
||||||
|
REDIS_URL="redis://@127.0.0.1:6379/4"
|
||||||
JWT_SECRET="secret"
|
JWT_SECRET="secret"
|
||||||
|
|
||||||
# Game configuration
|
# Game configuration
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "new-quest-server",
|
"name": "nq-server",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
@ -11,11 +11,11 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
socket.on('character:connect', async (data: SocketResponseT) => {
|
socket.on('character:connect', async (data: SocketResponseT) => {
|
||||||
console.log('character:connect requested', data)
|
console.log('character:connect requested', data)
|
||||||
try {
|
try {
|
||||||
const foundCharacter = await CharacterRepository.getByUserAndId(socket?.user?.id as number, data.character_id);
|
const character = await CharacterRepository.getByUserAndId(socket?.user?.id as number, data.character_id);
|
||||||
if(!foundCharacter) return;
|
if(!character) return;
|
||||||
socket.characterId = foundCharacter.id;
|
socket.characterId = character.id;
|
||||||
CharacterManager.initCharacter(foundCharacter as ExtendedCharacter);
|
CharacterManager.initCharacter(character as ExtendedCharacter);
|
||||||
socket.emit('character:connect', foundCharacter)
|
socket.emit('character:connect', character)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log('character:connect error', error)
|
console.log('character:connect error', error)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
import { TSocket } from '../../utilities/types'
|
|
||||||
import QueueManager from '../../managers/queueManager'
|
|
||||||
import CharacterMove from '../../events/zone/characterMove'
|
|
||||||
|
|
||||||
export default class CharacterListener {
|
|
||||||
constructor(private readonly io: Server, private readonly socket: TSocket) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public listen(): void {
|
|
||||||
this.socket.on('character:initMove', () => {
|
|
||||||
console.log('initmove?')
|
|
||||||
QueueManager.queue.add('myqueue', )
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
import IORedis from 'ioredis';
|
import IORedis from 'ioredis';
|
||||||
import { Job, Queue, Worker } from 'bullmq'
|
import { Job, Queue, Worker } from 'bullmq'
|
||||||
import CharacterJoin from '../events/zone/characterJoin'
|
import CharacterJoin from '../events/zone/characterJoin'
|
||||||
|
import config from '../utilities/config'
|
||||||
|
|
||||||
class QueueManager {
|
class QueueManager {
|
||||||
private connection!: IORedis;
|
private connection!: IORedis;
|
||||||
@ -8,19 +9,21 @@ class QueueManager {
|
|||||||
public worker!: Worker;
|
public worker!: Worker;
|
||||||
|
|
||||||
public boot() {
|
public boot() {
|
||||||
this.connection = new IORedis('redis://@127.0.0.1:6379/4', {
|
this.connection = new IORedis(config.REDIS_URL, {
|
||||||
maxRetriesPerRequest: null
|
maxRetriesPerRequest: null
|
||||||
});
|
});
|
||||||
this.queue = new Queue('myqueue', { connection: this.connection });
|
// this.queue = new Queue('myqueue', { connection: this.connection });
|
||||||
this.worker = new Worker('myqueue', async (job: Job)=>{
|
// this.worker = new Worker('myqueue', async (job: Job)=>{
|
||||||
console.log('hallo')
|
// console.log('hallo')
|
||||||
console.log(job.data);
|
// console.log(job.data);
|
||||||
console.log(job.data.data.classobj);
|
// console.log(job.data.data.classobj);
|
||||||
const test = job.data.data.classobj();
|
// const test = job.data.data.classobj();
|
||||||
console.log(test);
|
// console.log(test);
|
||||||
console.log(job.data);
|
// console.log(job.data);
|
||||||
}, { connection: this.connection, concurrency: 10000 });
|
// }, { connection: this.connection, concurrency: 10000 });
|
||||||
|
//
|
||||||
|
|
||||||
|
console.log('hallo')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import { Dirent } from 'node:fs'
|
|||||||
import { appLogger, watchLogs } from './utilities/logger'
|
import { appLogger, watchLogs } from './utilities/logger'
|
||||||
import CharacterManager from './managers/characterManager'
|
import CharacterManager from './managers/characterManager'
|
||||||
import QueueManager from './managers/queueManager'
|
import QueueManager from './managers/queueManager'
|
||||||
import CharacterListener from './listeners/zone/characterListener'
|
|
||||||
|
|
||||||
export class Server {
|
export class Server {
|
||||||
private readonly app: Application
|
private readonly app: Application
|
||||||
@ -88,7 +87,6 @@ export class Server {
|
|||||||
private async handleConnection(socket: TSocket) {
|
private async handleConnection(socket: TSocket) {
|
||||||
const eventsPath = path.join(__dirname, 'events')
|
const eventsPath = path.join(__dirname, 'events')
|
||||||
try {
|
try {
|
||||||
new CharacterListener(this.io, socket).listen();
|
|
||||||
await this.loadEventHandlers(eventsPath, socket)
|
await this.loadEventHandlers(eventsPath, socket)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
appLogger.error(`Failed to load event handlers: ${error.message}`)
|
appLogger.error(`Failed to load event handlers: ${error.message}`)
|
||||||
|
@ -4,6 +4,7 @@ dotenv.config()
|
|||||||
|
|
||||||
class config {
|
class config {
|
||||||
static ENV: string = process.env.ENV || 'prod'
|
static ENV: string = process.env.ENV || 'prod'
|
||||||
|
static REDIS_URL: string = process.env.REDIS_URL || 'redis://@127.0.0.1:6379/4'
|
||||||
static HOST: string = process.env.HOST || '0.0.0.0'
|
static HOST: string = process.env.HOST || '0.0.0.0'
|
||||||
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 6969
|
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 6969
|
||||||
static JWT_SECRET: string = process.env.JWT_SECRET || 'secret'
|
static JWT_SECRET: string = process.env.JWT_SECRET || 'secret'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user