-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move jobs to a separate project
Related to #83
- Loading branch information
1 parent
cf400c1
commit c035f6c
Showing
19 changed files
with
179 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@serieslist/eslint-config-base", | ||
"root": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@serieslist/prettier-config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM node:20-alpine AS base | ||
|
||
RUN npm i -g pnpm@8 | ||
|
||
|
||
FROM base AS dependencies | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies for compiling node-gyp (since there is no pre-built | ||
# binary for Alpine) | ||
# https://stackoverflow.com/a/59538284/7044732 | ||
RUN apk add g++ make python3 | ||
|
||
COPY . . | ||
|
||
RUN pnpm -F api --prod deploy pruned | ||
|
||
|
||
FROM dependencies AS build | ||
|
||
WORKDIR /app | ||
|
||
RUN rm -rf node_modules && rm -rf pruned && pnpm install | ||
RUN pnpm exec nx build @serieslist/api | ||
|
||
|
||
FROM base AS production | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app/apps/api/dist dist | ||
COPY --from=build /app/apps/api/package.json . | ||
COPY --from=dependencies /app/pruned/node_modules node_modules | ||
|
||
CMD [ "pnpm", "start:prod" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { buildEsbuild } from '@serieslist/core-esbuild' | ||
|
||
import pkg from '../package.json' | ||
|
||
await buildEsbuild({ | ||
packageJson: pkg, | ||
entryPoints: ['src/main.ts'], | ||
external: ['pg-native'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@serieslist/jobs", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"sideEffects": [ | ||
"src/**/*.job.ts" | ||
], | ||
"scripts": { | ||
"build": "rimraf dist && NODE_ENV=production tsx bin/build.ts", | ||
"build:docker": "(cd ../.. && docker buildx build --push --cache-to type=gha,mode=max,scope=webapp --cache-from type=gha,scope=webapp -t ghcr.io/joosepalviste/serieslist-jobs:latest -f apps/api/Dockerfile --target production .)", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"start": "NODE_ENV=development tsx watch --clear-screen=false src/main.ts", | ||
"start:prod": "NODE_ENV=production node dist/main.js", | ||
"tsc": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@serieslist/core-db": "workspace:*", | ||
"@serieslist/core-logger": "workspace:^", | ||
"@serieslist/feature-series-sync": "workspace:^", | ||
"bullmq": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@serieslist/core-esbuild": "workspace:*", | ||
"@serieslist/eslint-config-base": "workspace:*", | ||
"@serieslist/prettier-config": "workspace:*", | ||
"@serieslist/typescript-config-base": "workspace:*", | ||
"rimraf": "^4.4.0", | ||
"tsx": "^4.7.0", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
export const config = { | ||
redis: { | ||
host: process.env.REDIS_HOST!, | ||
port: parseInt(process.env.REDIS_PORT!), | ||
password: process.env.REDIS_PASSWORD!, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createDbConnection } from '@serieslist/core-db' | ||
|
||
import { log } from './logger' | ||
|
||
export const { db } = await createDbConnection({ logger: log }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createLogger } from '@serieslist/core-logger' | ||
|
||
export const log = createLogger({ name: 'jobs' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { reSyncSeries } from '@serieslist/feature-series-sync' | ||
|
||
import { createQueue, createWorker } from './lib/bullMq' | ||
import { db } from './lib/db' | ||
|
||
export const seriesSyncQueue = createQueue('seriesSync') | ||
|
||
const SERIES_SYNC_JOB = 'seriesSync' | ||
|
||
await seriesSyncQueue.add( | ||
SERIES_SYNC_JOB, | ||
{}, | ||
{ | ||
repeat: { | ||
pattern: '* * * * *', | ||
}, | ||
}, | ||
) | ||
|
||
export const seriesSyncWorker = createWorker( | ||
SERIES_SYNC_JOB, | ||
async () => { | ||
await reSyncSeries({ ctx: { db } }) | ||
}, | ||
{ autorun: false }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@serieslist/typescript-config-base", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.