Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal packages (testcontainers, redis-worker and zod-worker) #1392

Merged
merged 118 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
f02f2c0
Some notes on the new run engine
matt-aitken Sep 16, 2024
46a202f
lockfile with setup for the run engine
matt-aitken Sep 16, 2024
d11f422
Documenting where TaskRun is currently mutated, to try figure out the…
matt-aitken Sep 19, 2024
98a94a8
Added notes about how triggering currently works
matt-aitken Sep 19, 2024
1329b6a
Details about when triggering happens
matt-aitken Sep 19, 2024
670997e
Lots of notes about waitpoints
matt-aitken Sep 20, 2024
eef34a1
Started scaffolding the RunEngine
matt-aitken Sep 20, 2024
103bf42
Sketch of Prisma waitpoint schema while it’s fresh in my mind
matt-aitken Sep 20, 2024
0088b99
Got Prisma working with testcontainers
matt-aitken Sep 22, 2024
cb4fd95
Use beforeEach/afterEach
matt-aitken Sep 22, 2024
c1c8fd2
Simple Prisma and Redis test
matt-aitken Sep 22, 2024
3a3043e
Return Redis options instead of a client
matt-aitken Sep 22, 2024
7836229
Simplified things
matt-aitken Sep 22, 2024
9a9e8f1
A very simple FIFO pull-based queue to check the tests working properly
matt-aitken Sep 22, 2024
3d15109
Use vitest extend
matt-aitken Sep 22, 2024
a176954
Separate redis, postgres and combined tests for faster testing
matt-aitken Sep 22, 2024
a3cba4e
Some fixes and test improvements
matt-aitken Sep 23, 2024
a100ba3
Pass a logger into the queue
matt-aitken Sep 23, 2024
d919ba3
A queue processor that processes items from the given queue as fast a…
matt-aitken Sep 23, 2024
968f613
Test for retrying an item that wasn’t processed
matt-aitken Sep 23, 2024
539994c
First draft of waitpoints in the Prisma schema
matt-aitken Sep 23, 2024
e8190eb
Remove the custom logger from the test
matt-aitken Sep 23, 2024
969d6a7
Added a completedAt to Waitpoint
matt-aitken Sep 24, 2024
5d63c91
Notes on the flow for an execution starting
matt-aitken Sep 24, 2024
355b0ee
Merge remote-tracking branch 'origin/main' into run-engine
matt-aitken Sep 24, 2024
0121687
Added redlock, moved some files around
matt-aitken Sep 24, 2024
6d4da88
Starting point for the TaskRunExecutionSnapshot table
matt-aitken Sep 24, 2024
2297d8b
Added relationships to TaskRunExecutionSnapshot
matt-aitken Sep 24, 2024
7f50b36
Change some tsconfig
matt-aitken Sep 25, 2024
a3961da
Moved some things around
matt-aitken Sep 25, 2024
a236149
Added some packages
matt-aitken Sep 25, 2024
416fd88
WIP on the RunQueue
matt-aitken Sep 25, 2024
c3de286
Fix for some imports
matt-aitken Sep 26, 2024
08adc14
Key producer with some tests
matt-aitken Sep 26, 2024
8d13edc
Removed the nv type from the keys… it’s not useful to do global queries
matt-aitken Sep 26, 2024
0fa6bbf
Passing unit tests for all the public key producer functions
matt-aitken Sep 26, 2024
07e76d7
Some basic tests passing for the RunQueue
matt-aitken Sep 26, 2024
8f30533
Simple enqueue test working
matt-aitken Sep 26, 2024
ba8822f
Enqueue and dequeue for dev is working
matt-aitken Sep 26, 2024
63639d9
Don’t log everything during the tests
matt-aitken Sep 26, 2024
c06731a
Enqueuing/dequeuing from the shared queue is working
matt-aitken Sep 26, 2024
2b8ec70
Tests for getting a shared queue
matt-aitken Sep 26, 2024
87364f1
The key producer sharedQueue can now be named, to allow multiple sepa…
matt-aitken Sep 27, 2024
4265e6d
The key producer uses the name of the queue as the input
matt-aitken Sep 27, 2024
e69c127
Extra info in the Prisma schema
matt-aitken Sep 27, 2024
5de384f
Dequeuing a message gets the payload and sets the task concurrency al…
matt-aitken Sep 27, 2024
dc2d89e
Adding more keys so we can read the concurrency from the queue
matt-aitken Sep 27, 2024
8af3003
Setting the concurrency with dequeue and enquque is working
matt-aitken Sep 27, 2024
d2ed8ce
Improved the tests and fixed some bugs
matt-aitken Sep 27, 2024
a6175a7
Acking is resetting the concurrencies
matt-aitken Sep 27, 2024
58daf85
Check the key has been removed after acking
matt-aitken Sep 28, 2024
69b5c55
Nacking is working
matt-aitken Sep 29, 2024
e4993ec
Merge remote-tracking branch 'origin/main' into run-engine
matt-aitken Sep 29, 2024
4309819
Changed the package to CommonJS + Node10 so it works with Redlock
matt-aitken Sep 29, 2024
dbbc81d
Moved the database, otel and emails packages to be in internal-packages
matt-aitken Sep 29, 2024
82a0867
Moved some Prisma code to the database package
matt-aitken Sep 29, 2024
a20e180
Started using the RunEngine for triggering
matt-aitken Sep 29, 2024
f7d3c41
Progress on run engine triggering, first waitpoint code
matt-aitken Sep 30, 2024
c196ca6
Create a delay waitpoint
matt-aitken Sep 30, 2024
cf90b12
Moved ZodWorker to an internal package so it can be used in the run e…
matt-aitken Sep 30, 2024
99c3a96
Web app now uses the zod worker package
matt-aitken Sep 30, 2024
c902ce4
Added parseNaturalLanguageDuration to core/apps
matt-aitken Sep 30, 2024
cd36564
internal-packages/zod-worker in the lockfile
matt-aitken Sep 30, 2024
79733ca
Pass in the master queue, remove old rebalance workers code
matt-aitken Sep 30, 2024
bb214d2
Add masterQueue to TaskRun
matt-aitken Sep 30, 2024
534b060
Fixed the tests
matt-aitken Sep 30, 2024
3295597
Moved waitpoint code into the run engine, also the zod worker
matt-aitken Oct 1, 2024
f1232e5
Completing waitpoints
matt-aitken Oct 1, 2024
d958679
An experiment to create a new test container with environment
matt-aitken Oct 2, 2024
cb29349
More changes to triggering
matt-aitken Oct 2, 2024
f36b4b9
Started testing triggering
matt-aitken Oct 2, 2024
74d9523
Test for a run getting triggered and being enqueued
matt-aitken Oct 2, 2024
d632d48
Removed dequeueMessageInEnv
matt-aitken Oct 2, 2024
ad864d0
Update dev queue tests to use the shared queue function
matt-aitken Oct 2, 2024
e6cb27d
Schema changes for TaskRunExecutionSnapshot
matt-aitken Oct 2, 2024
8a78b14
First execution snapshot when the run is created. Dequeue run functio…
matt-aitken Oct 2, 2024
0bd237a
Merge remote-tracking branch 'origin/main' into run-engine
matt-aitken Oct 3, 2024
9927cdc
Separate internal package for testcontainers so they can be used else…
matt-aitken Oct 3, 2024
ae1c23d
Remove the simple queue and testcontainers from the run-engine. They’…
matt-aitken Oct 3, 2024
9f96eb3
Fix for the wrong path to the Prisma schem,a
matt-aitken Oct 3, 2024
28a922c
Added the testcontainers package to the run-engine
matt-aitken Oct 3, 2024
c779991
redis-worker package, just a copy of the simple queue for now
matt-aitken Oct 3, 2024
be98dbf
The queue now uses Lua to enqueue dequeue
matt-aitken Oct 3, 2024
3d0bbac
The queue now has a catalog and an invisible period after dequeuing
matt-aitken Oct 4, 2024
a7e114c
Added a visibility timeout and acking, with tests
matt-aitken Oct 4, 2024
75c2ad3
Added more Redis connection logging, deleted todos
matt-aitken Oct 4, 2024
d806516
Visibility timeouts are now defined on the catalog and can be overrid…
matt-aitken Oct 4, 2024
4a1fd0d
Dequeue multiple items at once
matt-aitken Oct 4, 2024
c8ce878
Test for dequeuing multiple items
matt-aitken Oct 4, 2024
cd2cfb9
Export some types to be used elsewhere
matt-aitken Oct 4, 2024
7d8db07
Partial refactor of the processor
matt-aitken Oct 4, 2024
1c31aa0
First stab at a worker with concurrency and NodeWorkers
matt-aitken Oct 4, 2024
fff3a35
Don’t have a default visibility timeout in the queue
matt-aitken Oct 4, 2024
9e2b9e0
Worker setup and processing items in a simple test
matt-aitken Oct 5, 2024
b8d7380
Process jobs in parallel with retrying
matt-aitken Oct 5, 2024
461ec42
Get the attempt when dequeuing
matt-aitken Oct 6, 2024
1a713b0
Workers do exponential backoff
matt-aitken Oct 6, 2024
eee5649
Moved todos
matt-aitken Oct 6, 2024
0c25754
DLQ functionality
matt-aitken Oct 8, 2024
aa84a69
DLQ tests
matt-aitken Oct 8, 2024
62c8b2c
Same cluster for all keys in the same queue
matt-aitken Oct 8, 2024
da02da9
Added DLQ tests
matt-aitken Oct 8, 2024
decf826
Whitespace
matt-aitken Oct 8, 2024
d5fdf7f
Redis pubsub to redrive from the worker
matt-aitken Oct 8, 2024
844cb77
Fixed database paths
matt-aitken Oct 8, 2024
25ee43b
Fix for path to zod-worker
matt-aitken Oct 8, 2024
932dd5e
Fixes for typecheck errors, mostly with TS versions and module resolu…
matt-aitken Oct 8, 2024
c0ad065
Redlock required a patch
matt-aitken Oct 8, 2024
83beca2
Merge remote-tracking branch 'origin/main' into run-engine
matt-aitken Oct 8, 2024
2664c1d
Moved the new DB migrations to the new database package folder
matt-aitken Oct 8, 2024
386ee00
Remove the run-engine package
matt-aitken Oct 8, 2024
e1bba09
Remove the RunEngine prisma schema changes
matt-aitken Oct 8, 2024
7d05c97
Delete triggerTaskV2
matt-aitken Oct 8, 2024
60e7b5f
Remove zodworker test script (no tests)
matt-aitken Oct 8, 2024
1254649
Update test-containers readme
matt-aitken Oct 8, 2024
d328d71
Generate the client first
matt-aitken Oct 8, 2024
1f6c86d
Use a specific version of the prisma package
matt-aitken Oct 8, 2024
08cde55
Generate the prisma client before running the unit tests
matt-aitken Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Separate internal package for testcontainers so they can be used else…
…where
matt-aitken committed Oct 3, 2024
commit 9927cdc6b2b0d52fd188b31d5be93bee646711ee
1 change: 1 addition & 0 deletions internal-packages/run-engine/package.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@internal/testcontainers": "workspace:*",
"@internal/zod-worker": "workspace:*",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
2 changes: 1 addition & 1 deletion internal-packages/run-engine/src/engine/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "vitest";
import { containerTest } from "../test/containerTest.js";
import { containerTest } from "@internal/testcontainers";
import { RunEngine } from "./index.js";
import { PrismaClient, RuntimeEnvironmentType } from "@trigger.dev/database";

2 changes: 1 addition & 1 deletion internal-packages/run-engine/src/run-queue/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { trace } from "@opentelemetry/api";
import { Logger } from "@trigger.dev/core/logger";
import { describe } from "node:test";
import { redisTest } from "../test/containerTest.js";
import { redisTest } from "@internal/testcontainers";
import { RunQueue } from "./index.js";
import { RunQueueShortKeyProducer } from "./keyProducer.js";
import { SimpleWeightedChoiceStrategy } from "./simpleWeightedPriorityStrategy.js";
2 changes: 2 additions & 0 deletions internal-packages/run-engine/tsconfig.json
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
"noEmit": true,
"strict": true,
"paths": {
"@internal/testcontainers": ["../../internal-packages/testcontainers/src/index"],
"@internal/testcontainers/*": ["../../internal-packages/testcontainers/src/*"],
"@internal/zod-worker": ["../../internal-packages/zod-worker/src/index"],
"@internal/zod-worker/*": ["../../internal-packages/zod-worker/src/*"],
"@trigger.dev/core": ["../../packages/core/src/index"],
10 changes: 10 additions & 0 deletions internal-packages/testcontainers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Redis worker

This is a simple worker that pulls tasks from a Redis queue (also in this package).

Features

- Configurable settings for concurrency and pull speed.
- Job payloads.
- A schema so only defined jobs can be added to the queue.
- The ability to have future dates for jobs.
22 changes: 22 additions & 0 deletions internal-packages/testcontainers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@internal/testcontainers",
"private": true,
"version": "0.0.1",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@trigger.dev/database": "workspace:*",
"ioredis": "^5.3.2",
"typescript": "^4.8.4"
},
"devDependencies": {
"@testcontainers/postgresql": "^10.13.1",
"@testcontainers/redis": "^10.13.1",
"testcontainers": "^10.13.1",
"vitest": "^1.4.0"
},
"scripts": {
"typecheck": "tsc --noEmit"
}
}
67 changes: 67 additions & 0 deletions internal-packages/testcontainers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { StartedPostgreSqlContainer } from "@testcontainers/postgresql";
import { StartedRedisContainer } from "@testcontainers/redis";
import { Redis } from "ioredis";
import { test } from "vitest";
import { PrismaClient } from "@trigger.dev/database";
import { createPostgresContainer, createRedisContainer } from "./utils";

type PostgresContext = {
postgresContainer: StartedPostgreSqlContainer;
prisma: PrismaClient;
};

type RedisContext = { redisContainer: StartedRedisContainer; redis: Redis };
type ContainerContext = PostgresContext & RedisContext;

type Use<T> = (value: T) => Promise<void>;

const postgresContainer = async ({}, use: Use<StartedPostgreSqlContainer>) => {
const { container } = await createPostgresContainer();
await use(container);
await container.stop();
};

const prisma = async (
{ postgresContainer }: { postgresContainer: StartedPostgreSqlContainer },
use: Use<PrismaClient>
) => {
const prisma = new PrismaClient({
datasources: {
db: {
url: postgresContainer.getConnectionUri(),
},
},
});
await use(prisma);
await prisma.$disconnect();
};

export const postgresTest = test.extend<PostgresContext>({ postgresContainer, prisma });

const redisContainer = async ({}, use: Use<StartedRedisContainer>) => {
const { container } = await createRedisContainer();
await use(container);
await container.stop();
};

const redis = async (
{ redisContainer }: { redisContainer: StartedRedisContainer },
use: Use<Redis>
) => {
const redis = new Redis({
host: redisContainer.getHost(),
port: redisContainer.getPort(),
password: redisContainer.getPassword(),
});
await use(redis);
await redis.quit();
};

export const redisTest = test.extend<RedisContext>({ redisContainer, redis });

export const containerTest = test.extend<ContainerContext>({
postgresContainer,
prisma,
redisContainer,
redis,
});
35 changes: 35 additions & 0 deletions internal-packages/testcontainers/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PostgreSqlContainer } from "@testcontainers/postgresql";
import { RedisContainer } from "@testcontainers/redis";
import { execSync } from "child_process";
import path from "path";

export async function createPostgresContainer() {
const container = await new PostgreSqlContainer().start();

// Run migrations
const databasePath = path.resolve(__dirname, "../../../database");

execSync(`npx prisma db push --schema ${databasePath}/prisma/schema.prisma`, {
env: {
...process.env,
DATABASE_URL: container.getConnectionUri(),
DIRECT_URL: container.getConnectionUri(),
},
});

// console.log(container.getConnectionUri());

return { url: container.getConnectionUri(), container };
}

export async function createRedisContainer() {
const container = await new RedisContainer().start();
try {
return {
container,
};
} catch (e) {
console.error(e);
throw e;
}
}
25 changes: 25 additions & 0 deletions internal-packages/testcontainers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2019",
"lib": ["ES2019", "DOM", "DOM.Iterable"],
"module": "CommonJS",
"moduleResolution": "Node10",
"moduleDetection": "force",
"verbatimModuleSyntax": false,
"types": ["vitest/globals"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"preserveWatchOutput": true,
"skipLibCheck": true,
"noEmit": true,
"strict": true,
"paths": {
"@trigger.dev/core": ["../../packages/core/src/index"],
"@trigger.dev/core/*": ["../../packages/core/src/*"],
"@trigger.dev/database": ["../../internal-packages/database/src/index"],
"@trigger.dev/database/*": ["../../internal-packages/database/src/*"]
}
},
"exclude": ["node_modules"]
}
8 changes: 8 additions & 0 deletions internal-packages/testcontainers/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.test.ts"],
globals: true,
},
});