Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

Refactor: Use ExportJobCleanupItem interface in RedisJobStore

Cursor Agent0cace978307f
diff --git a/lib/redis-job-store.ts b/lib/redis-job-store.ts
index fe9345a0..6d967536 100644
--- a/lib/redis-job-store.ts
+++ b/lib/redis-job-store.ts
@@ -23,6 +23,12 @@ export interface ExportJob {
emailAddress?: string;
}
+export interface ExportJobCleanupItem {
+ blobUrl: string;
+ jobId: string;
+ scheduledAt: string;
+}
+
const JOB_PREFIX = "export_job:";
const USER_JOBS_PREFIX = "user_jobs:";
const TEAM_JOBS_PREFIX = "team_jobs:";
@@ -141,7 +147,7 @@ export class RedisJobStore {
async getBlobsForCleanup(
beforeTimestamp?: number,
- ): Promise<Array<{ blobUrl: string; jobId: string; scheduledAt: string }>> {
+ ): Promise<Array<ExportJobCleanupItem>> {
const cleanupQueueKey = this.getCleanupQueueKey();
const maxScore = beforeTimestamp || Date.now();
@@ -150,18 +156,14 @@ export class RedisJobStore {
byScore: true,
});
- const blobs: Array<{
- blobUrl: string;
- jobId: string;
- scheduledAt: string;
- }> = [];
+ const blobs: Array<ExportJobCleanupItem> = [];
for (const item of items) {
try {
- let parsed;
+ let parsed: ExportJobCleanupItem;
// Check if data is already an object (Redis client auto-parsed)
if (typeof item === "object" && item !== null) {
- parsed = item as { blobUrl: string; jobId: string; scheduledAt: string };
+ parsed = item as ExportJobCleanupItem;
} else {
// Otherwise parse the JSON string
parsed = JSON.parse(item as string);
diff --git a/pages/api/teams/[teamId]/export-jobs/[exportId].ts b/pages/api/teams/[teamId]/export-jobs/[exportId].ts
index f883d39b..db1ce55c 100644
--- a/pages/api/teams/[teamId]/export-jobs/[exportId].ts
+++ b/pages/api/teams/[teamId]/export-jobs/[exportId].ts
@@ -3,6 +3,8 @@ import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
+import { runs } from "@trigger.dev/sdk/v3";
+
import { jobStore } from "@/lib/redis-job-store";
import { CustomUser } from "@/lib/types";
@@ -88,7 +90,7 @@ export default async function handler(
// Cancel the trigger run if we have the run ID
if (exportJob.triggerRunId) {
try {
- const { runs } = await import("@trigger.dev/sdk/v3");
+
await runs.cancel(exportJob.triggerRunId);
} catch (error) {
console.error("Failed to cancel trigger run:", error);