Skip to content

Commit

Permalink
update runner opts
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Sep 20, 2023
1 parent f7301f1 commit 7103a27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const job20230920_update_services = {
tagId: 'svtg_01HAD99DSF7TH2HDXNYC331BVN',
active: true,
})),
skipDuplicates: true,
})
log(`Created ${gaCareTag.count} tags for ${tGaCare.length} services`)
})
Expand Down
29 changes: 16 additions & 13 deletions packages/db/prisma/dataMigrationRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import {
Listr,
type ListrDefaultRenderer,
type ListrSimpleRenderer,
type ListrTask as ListrTaskObj,
type ListrTaskWrapper,
PRESET_TIMER,
PRESET_TIMESTAMP,
} from 'listr2'

import { prisma } from '~db/client'
Expand All @@ -18,12 +20,13 @@ import * as jobList from './data-migrations'
* You shouldn't need to touch anything in this file. All jobs in `data-migrations/index.ts` will be imported.
*/

const renderOptions = {
bottomBar: 10,
const rendererOptions = {
outputBar: 10,
persistentOutput: true,
timer: PRESET_TIMER,
} satisfies ListrJob['options']
const injectOptions = (job: ListrJob): ListrJob => ({ ...job, options: renderOptions })
} satisfies ListrJob['rendererOptions']

const injectOptions = (job: ListrJob): ListrJob => ({ ...job, rendererOptions })

const jobQueue: ListrJob[] = []

Expand All @@ -50,37 +53,37 @@ const jobs = new Listr<Context>(
if (jobNamesToRun.length) {
ctx.pendingMigrations = true
ctx.jobCount = jobNamesToRun.length
task.output = `${jobNamesToRun.length} migrations to run:\n${jobNamesToRun.join('\n')}`
task.output = `${jobNamesToRun.length} migrations to run:\n${jobNamesToRun.join('\n')}`
task.title = `Pending migrations: ${jobNamesToRun.length}`
} else {
task.title = `No pending migrations`
task.title = `No pending migrations to apply.`
}
},
...renderOptions,

rendererOptions: { ...rendererOptions, timer: { condition: false, field: '' } },
},
{
title: `Apply ${jobQueue.length} pending migrations`,
task: (ctx, task) => {
task.title = `Apply ${ctx.jobCount ?? 0} pending migrations`
task.title = `Applying ${ctx.jobCount ?? 0} pending migrations`
return task.newListr(jobQueue)
},
enabled: (ctx) => !!ctx.pendingMigrations,
...renderOptions,
rendererOptions,
},
// ...Object.values(jobList).map((job) => injectOptions(job)),
],
{
rendererOptions: {
formatOutput: 'wrap',
timer: PRESET_TIMER,
suffixSkips: true,
collapseSubtasks: false,
removeEmptyLines: false,
},
fallbackRendererOptions: {
timer: PRESET_TIMER,
timestamp: PRESET_TIMESTAMP,
},
exitOnError: false,
forceColor: true,
}
)

Expand All @@ -91,7 +94,7 @@ export type Context = {
pendingMigrations?: boolean
jobCount?: number
}
export type PassedTask = ListrTaskWrapper<Context, ListrDefaultRenderer>
export type PassedTask = ListrTaskWrapper<Context, ListrDefaultRenderer, ListrSimpleRenderer>
export type ListrJob = ListrTaskObj<Context, ListrDefaultRenderer>

export type MigrationJob = ListrJob & { def: JobDef }
Expand Down
4 changes: 2 additions & 2 deletions packages/db/prisma/jobPreRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import path from 'path'
import { type PassedTask } from './dataMigrationRunner'
import { prisma } from '..'

const getTimestamp = () => DateTime.now().toLocaleString(DateTime.TIME_24_WITH_SECONDS).replaceAll(':', '.')
const getTimestamp = () => DateTime.now().toFormat('yyyy-MM-dd_HH.mm.ss')

const logFile = (file: string, output: string) => {
const timestamp = DateTime.now().toFormat('yyyy-MM-dd HH:mm:ss')
const timestamp = DateTime.now().toFormat('yyyy-MM-dd HH:mm:ss.SSS')
const outFile = path.resolve(__dirname, './migration-logs/', file)
const formattedOutput = `[${timestamp}] ${output}\n`
fs.writeFileSync(outFile, formattedOutput, { flag: 'a' })
Expand Down

0 comments on commit 7103a27

Please sign in to comment.