Skip to content

Commit 22577c2

Browse files
committed
add timestamp to clickhouse
1 parent 52ac1e1 commit 22577c2

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- +goose Up
2+
ALTER TABLE trigger_dev.task_runs_v2
3+
ADD COLUMN IF NOT EXISTS queue_timestamp Nullable(DateTime64(3)) AFTER created_at;
4+
5+
-- +goose Down
6+
ALTER TABLE trigger_dev.task_runs_v2
7+
DROP COLUMN IF EXISTS queue_timestamp;

internal-packages/clickhouse/src/taskRuns.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ describe("Task Runs V2", () => {
2929
});
3030

3131
const now = Date.now();
32+
const queueTimestamp = now + 30_000;
3233
const taskRunData: TaskRunInsertArray = [
3334
"env_1234", // environment_id
3435
"org_1234", // organization_id
3536
"project_1234", // project_id
3637
"run_1234", // run_id
3738
now, // updated_at
3839
now, // created_at
40+
queueTimestamp, // queue_timestamp
3941
"PENDING", // status
4042
"DEVELOPMENT", // environment_type
4143
"friendly_1234", // friendly_id
@@ -105,6 +107,7 @@ describe("Task Runs V2", () => {
105107
schema: z.object({
106108
environment_id: z.string(),
107109
run_id: z.string(),
110+
queue_timestamp: z.coerce.date().nullable(),
108111
concurrency_key: z.string(),
109112
bulk_action_group_ids: z.array(z.string()),
110113
}),
@@ -121,6 +124,7 @@ describe("Task Runs V2", () => {
121124
expect.objectContaining({
122125
environment_id: "env_1234",
123126
run_id: "run_1234",
127+
queue_timestamp: new Date(queueTimestamp),
124128
concurrency_key: "concurrency_key_1234",
125129
bulk_action_group_ids: ["bulk_action_group_id_1234", "bulk_action_group_id_1235"],
126130
}),
@@ -183,6 +187,7 @@ describe("Task Runs V2", () => {
183187
"run_mixed", // run_id
184188
now, // updated_at
185189
now, // created_at
190+
null, // queue_timestamp
186191
"COMPLETED_SUCCESSFULLY", // status
187192
"DEVELOPMENT", // environment_type
188193
"friendly_mixed", // friendly_id
@@ -282,6 +287,7 @@ describe("Task Runs V2", () => {
282287
"cma45oli70002qrdy47w0j4n7", // run_id
283288
createdAt, // updated_at
284289
createdAt, // created_at
290+
null, // queue_timestamp
285291
"PENDING", // status
286292
"PRODUCTION", // environment_type
287293
"run_cma45oli70002qrdy47w0j4n7", // friendly_id
@@ -339,6 +345,7 @@ describe("Task Runs V2", () => {
339345
"cma45oli70002qrdy47w0j4n7", // run_id
340346
createdAt, // updated_at
341347
createdAt, // created_at
348+
null, // queue_timestamp
342349
"COMPLETED_SUCCESSFULLY", // status
343350
"PRODUCTION", // environment_type
344351
"run_cma45oli70002qrdy47w0j4n7", // friendly_id
@@ -443,6 +450,7 @@ describe("Task Runs V2", () => {
443450
"cma45oli70002qrdy47w0j4n7", // run_id
444451
createdAt, // updated_at
445452
createdAt, // created_at
453+
null, // queue_timestamp
446454
"PENDING", // status
447455
"PRODUCTION", // environment_type
448456
"run_cma45oli70002qrdy47w0j4n7", // friendly_id
@@ -555,6 +563,7 @@ describe("Task Runs V2", () => {
555563
"root_run_1", // run_id
556564
baseCreatedAt, // updated_at
557565
baseCreatedAt, // created_at
566+
null, // queue_timestamp
558567
"EXECUTING", // status
559568
"DEVELOPMENT", // environment_type
560569
"run_root_1", // friendly_id
@@ -612,6 +621,7 @@ describe("Task Runs V2", () => {
612621
"child_a",
613622
baseCreatedAt + 1_000,
614623
baseCreatedAt + 1_000,
624+
null, // queue_timestamp
615625
"PENDING",
616626
"DEVELOPMENT",
617627
"run_child_a",
@@ -673,6 +683,7 @@ describe("Task Runs V2", () => {
673683
"child_b",
674684
baseCreatedAt + 2_000,
675685
baseCreatedAt + 2_000,
686+
null, // queue_timestamp
676687
"EXECUTING",
677688
"DEVELOPMENT",
678689
"run_child_b",
@@ -730,6 +741,7 @@ describe("Task Runs V2", () => {
730741
"child_deleted",
731742
baseCreatedAt + 3_000,
732743
baseCreatedAt + 3_000,
744+
null, // queue_timestamp
733745
"PENDING",
734746
"DEVELOPMENT",
735747
"run_child_deleted",
@@ -907,6 +919,7 @@ describe("Task Runs V2", () => {
907919
"cma45oli70002qrdy47w0j4n7",
908920
createdAt,
909921
createdAt,
922+
null, // queue_timestamp
910923
"PENDING",
911924
"PRODUCTION",
912925
"run_cma45oli70002qrdy47w0j4n7",
@@ -1010,6 +1023,7 @@ describe("Task Runs V2", () => {
10101023
"cma45oli70002qrdy47w0j4n7",
10111024
createdAt,
10121025
createdAt,
1026+
null, // queue_timestamp
10131027
"PENDING",
10141028
"PRODUCTION",
10151029
"run_cma45oli70002qrdy47w0j4n7",
@@ -1113,6 +1127,7 @@ describe("Task Runs V2", () => {
11131127
"cma45oli70002qrdy47w0j4n7",
11141128
createdAt,
11151129
createdAt,
1130+
null, // queue_timestamp
11161131
"PENDING",
11171132
"PRODUCTION",
11181133
"run_cma45oli70002qrdy47w0j4n7",

internal-packages/clickhouse/src/taskRuns.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const TaskRunV2 = z.object({
99
run_id: z.string(),
1010
updated_at: z.number().int(),
1111
created_at: z.number().int(),
12+
queue_timestamp: z.number().int().nullish(),
1213
status: z.string(),
1314
environment_type: z.string(),
1415
friendly_id: z.string(),
@@ -69,6 +70,7 @@ export const TASK_RUN_COLUMNS = [
6970
"run_id",
7071
"updated_at",
7172
"created_at",
73+
"queue_timestamp",
7274
"status",
7375
"environment_type",
7476
"friendly_id",
@@ -138,6 +140,7 @@ export type TaskRunFieldTypes = {
138140
run_id: string;
139141
updated_at: number;
140142
created_at: number;
143+
queue_timestamp: number | null;
141144
status: string;
142145
environment_type: string;
143146
friendly_id: string;
@@ -306,6 +309,7 @@ export type TaskRunInsertArray = [
306309
run_id: string,
307310
updated_at: number,
308311
created_at: number,
312+
queue_timestamp: number | null,
309313
status: string,
310314
environment_type: string,
311315
friendly_id: string,

0 commit comments

Comments
 (0)