Skip to content

Commit

Permalink
Merge pull request #45 from HugoRCD/feat/44
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD authored Dec 29, 2024
2 parents dac3366 + f351b50 commit 29f3866
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apps/formatter/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
//https://nitro.unjs.io/config
export default defineNitroConfig({
srcDir: 'server',

experimental: {
tasks: true
}
},

scheduledTasks: {
'* * * * *': ['sync:mongo']
},

compatibilityDate: '2024-12-29'
})
3 changes: 2 additions & 1 deletion apps/formatter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"build": "nitro build",
"dev": "nitro dev",
"prepare": "nitro prepare",
"preview": "node .output/server/index.mjs"
"preview": "node .output/server/index.mjs",
"sync:mongo": "nitro task run sync:mongo"
},
"devDependencies": {
"nitropack": "latest",
Expand Down
16 changes: 16 additions & 0 deletions apps/formatter/server/tasks/sync/mongo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MongoDBClient } from '@currencia/mongo'

export default defineTask({
meta: {
name: 'sync:mongo',
description: 'Send MongoID to RabbitMQ',
},
async run() {
const client = await MongoDBClient.create()
console.log('Syncing MongoID to RabbitMQ')
const price = await client.getLatestPrices()
console.log('Price:', price)
console.log('Ids to sync:', price?._id)
return { result: 'Success' }
},
})
1 change: 1 addition & 0 deletions packages/mongo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type MongoConfig = {
}

type PriceDocument = {
_id?: string
timestamp: Date
prices: Record<string, number>
}
Expand Down

0 comments on commit 29f3866

Please sign in to comment.