@checkstack/gitops-backend 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @checkstack/gitops-backend
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 79cf5f8: ### GitOps: Fix sync lifecycle management
8
+
9
+ - Schedule recurring sync job immediately when creating a provider (previously required server restart)
10
+ - Reschedule recurring job when provider's sync interval is updated
11
+ - Cancel recurring job when provider is deleted
12
+ - Fix manual sync trigger being silently dropped due to job ID deduplication
13
+
3
14
  ## 0.1.1
4
15
 
5
16
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/gitops-backend",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "checkstack": {
package/src/router.ts CHANGED
@@ -5,7 +5,7 @@ import { gitopsContract } from "@checkstack/gitops-common";
5
5
  import type { SafeDatabase } from "@checkstack/backend-api";
6
6
  import type { QueueManager } from "@checkstack/queue-api";
7
7
  import type { InternalEntityKindRegistry } from "./kind-registry";
8
- import { triggerSyncForProvider } from "./sync/sync-worker";
8
+ import { triggerSyncForProvider, scheduleSyncForProvider, cancelSyncForProvider } from "./sync/sync-worker";
9
9
  import * as schema from "./schema";
10
10
  import { eq, and } from "drizzle-orm";
11
11
  import { v4 as uuidv4 } from "uuid";
@@ -82,6 +82,7 @@ export const createGitOpsRouter = ({
82
82
 
83
83
  const createProvider = os.createProvider.handler(async ({ input }) => {
84
84
  const id = uuidv4();
85
+ const syncInterval = input.syncInterval ?? 300;
85
86
  await db.insert(schema.providers).values({
86
87
  id,
87
88
  type: input.type,
@@ -89,9 +90,17 @@ export const createGitOpsRouter = ({
89
90
  pathPattern: input.pathPattern,
90
91
  baseUrl: input.baseUrl ?? null, // eslint-disable-line unicorn/no-null
91
92
  authToken: input.authToken ? encrypt(input.authToken) : null, // eslint-disable-line unicorn/no-null
92
- syncInterval: input.syncInterval ?? 300,
93
+ syncInterval,
93
94
  deletionPolicy: input.deletionPolicy ?? "orphan",
94
95
  });
96
+
97
+ // Schedule recurring sync for the new provider
98
+ await scheduleSyncForProvider({
99
+ queueManager,
100
+ providerId: id,
101
+ syncIntervalSeconds: syncInterval,
102
+ });
103
+
95
104
  return { id };
96
105
  });
97
106
 
@@ -127,6 +136,15 @@ export const createGitOpsRouter = ({
127
136
  .set(updates)
128
137
  .where(eq(schema.providers.id, input.id));
129
138
 
139
+ // If syncInterval changed, reschedule the recurring job
140
+ if (input.data.syncInterval !== undefined) {
141
+ await scheduleSyncForProvider({
142
+ queueManager,
143
+ providerId: input.id,
144
+ syncIntervalSeconds: input.data.syncInterval,
145
+ });
146
+ }
147
+
130
148
  return { success: true };
131
149
  });
132
150
 
@@ -145,6 +163,12 @@ export const createGitOpsRouter = ({
145
163
  // Provenance entries are cascade-deleted via FK constraint
146
164
  await db.delete(schema.providers).where(eq(schema.providers.id, input.id));
147
165
 
166
+ // Cancel the recurring sync job
167
+ await cancelSyncForProvider({
168
+ queueManager,
169
+ providerId: input.id,
170
+ });
171
+
148
172
  return { success: true };
149
173
  });
150
174
 
@@ -165,8 +165,18 @@ export async function triggerSyncForProvider(params: {
165
165
  const { queueManager, providerId } = params;
166
166
  const queue = queueManager.getQueue<SyncJobPayload>(SYNC_QUEUE);
167
167
 
168
- await queue.enqueue(
169
- { providerId },
170
- { jobId: `gitops-sync-${providerId}-manual` },
171
- );
168
+ await queue.enqueue({ providerId });
169
+ }
170
+
171
+ /**
172
+ * Cancels the recurring sync job for a provider (used when deleting a provider).
173
+ */
174
+ export async function cancelSyncForProvider(params: {
175
+ queueManager: QueueManager;
176
+ providerId: string;
177
+ }): Promise<void> {
178
+ const { queueManager, providerId } = params;
179
+ const queue = queueManager.getQueue<SyncJobPayload>(SYNC_QUEUE);
180
+
181
+ await queue.cancelRecurring(`gitops-sync-${providerId}`);
172
182
  }