Skip to content

Commit

Permalink
better debug logs for library sync
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Dec 9, 2024
1 parent 79d26c3 commit aac5e90
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions apps/playnite-web/src/server/mqttUpdater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IDeleteQuery, IQuery, IUpdateQuery } from '../data/types.api.js'
import { PubSubChannels } from '../graphql/subscriptionPublisher.js'
import handlers from './handlers/index.js'

const debug = createDebugger('playnite-web/game-db-updater/index')

type HandlerOptions = {
assetSaveDirectoryPath: string
pubsub: PubSub<PubSubChannels>
Expand All @@ -16,21 +18,36 @@ type HandlerOptions = {
}

const batchTopic = /^playnite\/[^/]+\/batch$/
const librarySync = /^playnite\/[^/]+\/library\/sync\/(.*)$/

const mqttUpdater = async (options: HandlerOptions): Promise<void> => {
const debug = createDebugger('playnite-web/game-db-updater/index')
debug('Starting game-db-updater')

options.mqtt.subscribe('playnite/#')

await fs.mkdir(options.assetSaveDirectoryPath, { recursive: true })

let syncMessageCount = 0
options.mqtt.on('message', async (topic, payload) => {
const librarySyncMessageMatches = librarySync.exec(topic)
if (librarySyncMessageMatches?.[1] === 'start') {
syncMessageCount = 0
return
}
if (librarySyncMessageMatches?.[1] === 'completed') {
debug(
`Library sync completed. Processed a total of ${syncMessageCount} database entities. This number should match the number of all documents, across all collections, in your games database.`,
)
return
}

let messages: Array<{ topic: string; payload: Buffer }> = []
if (batchTopic.test(topic)) {
messages = JSON.parse(payload.toString()).messages
console.log('Batched messages received', messages.length)
syncMessageCount += messages.length
debug('Batched messages received', messages.length)
} else {
syncMessageCount += 1
messages.push({ topic, payload })
}

Expand Down

0 comments on commit aac5e90

Please sign in to comment.