Skip to content

Commit

Permalink
feat: insert the results into the database
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed May 27, 2024
1 parent 1cd877e commit fe02b8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 13 additions & 3 deletions service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const vlmcsdServers = [
]

const runVlmcs = (server: string) => {
return new Promise(resolve => {
return new Promise<{
content: string
delay: number
server: string
status: boolean
}>(resolve => {
const before = Date.now()
execFile(
`./service/binaries/vlmcs-${platform()}-${arch()}`,
Expand All @@ -33,7 +38,7 @@ const runVlmcs = (server: string) => {
server,
status: err ? false : true,
})
}
},
)
})
}
Expand All @@ -43,7 +48,12 @@ new CronJob(
async function () {
for (const item of vlmcsdServers) {
const result = await runVlmcs(item)
console.log(result)
db.insert(schema.logs)
.values({
...result,
createdAt: Date.now(),
})
.run()
}
},
null,
Expand Down
13 changes: 8 additions & 5 deletions service/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'

export const logs = sqliteTable("logs", {
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
createdAt: integer("created_at").notNull(),
});
export const logs = sqliteTable('logs', {
id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),
server: text('server').notNull(),
status: integer('status', { mode: 'boolean' }).notNull(),
delay: integer('delay').notNull(),
createdAt: integer('created_at').notNull(),
})

0 comments on commit fe02b8c

Please sign in to comment.