mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
wip: removing console log
This commit is contained in:
1 parent
515aefcadc
commit
82d1004ecf
16 files changed
+57
-34
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import Docker from 'dockerode'
|
||||
import config, { getQuestImage } from '../config.js'
|
||||
import logger from '../utils/logger.js'
|
||||
|
||||
const engine = new Docker()
|
||||
|
||||
@@ -33,7 +34,7 @@ export function createContainer(name, questId) {
|
||||
}
|
||||
|
||||
export async function getAndStartContainer(id) {
|
||||
console.log(`Getting container: ${id}`)
|
||||
logger.debug(`Getting container: ${id}`)
|
||||
const container = engine.getContainer(id)
|
||||
if (!container) {
|
||||
throw new Error(`Container ${id} not found`)
|
||||
@@ -74,7 +75,7 @@ export async function deleteContainer(id) {
|
||||
try {
|
||||
await container.stop()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
logger.warn(error)
|
||||
}
|
||||
await container.remove()
|
||||
}
|
||||
@@ -99,21 +100,21 @@ export function buildQuestImage(questPath, questId) {
|
||||
// Process the data (this could be Docker build output)
|
||||
const { stream, error } = JSON.parse(data.toString())
|
||||
if (stream) {
|
||||
console.log(stream)
|
||||
logger.info(stream)
|
||||
}
|
||||
if (error) {
|
||||
console.error(error)
|
||||
logger.error(error)
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
|
||||
response.on('end', () => {
|
||||
console.log(`Build completed for ${questId}`)
|
||||
logger.info(`Build completed for ${questId}`)
|
||||
resolve(questId)
|
||||
})
|
||||
|
||||
response.on('error', (error) => {
|
||||
console.error(`Build failed for ${questId}:`, error)
|
||||
logger.error(`Build failed for ${questId}:`, error)
|
||||
reject(error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@ import schedule from 'node-schedule'
|
||||
import { Session } from '@linux-odyssey/models'
|
||||
import config from '../config.js'
|
||||
import { deleteContainer } from './docker.js'
|
||||
import logger from '../utils/logger.js'
|
||||
|
||||
export async function removeExpired() {
|
||||
// Find all sessions that are containerId is not null and lastActivityAt is
|
||||
// less than the current time minus the expiry time
|
||||
try {
|
||||
console.log('Checking for expired sessions')
|
||||
const sessions = await Session.find({
|
||||
containerId: { $ne: null },
|
||||
lastActivityAt: { $lt: new Date(Date.now() - config.containerExpiry) },
|
||||
})
|
||||
await Promise.all(
|
||||
sessions.map(async (session) => {
|
||||
console.log('Expiring session: ', session._id, session.containerId)
|
||||
logger.info('Expiring session: ', session._id, session.containerId)
|
||||
try {
|
||||
await deleteContainer(session.containerId)
|
||||
} catch (err) {
|
||||
@@ -29,9 +29,8 @@ export async function removeExpired() {
|
||||
await session.save()
|
||||
})
|
||||
)
|
||||
console.log('Done checking for expired sessions')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user