Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions apps/sim/lib/core/idempotency/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ describe('IdempotencyService in-progress deadlines', () => {

const conflictOptions = dbChainMockFns.onConflictDoUpdate.mock.calls[0]?.[0]
const setWhere = JSON.stringify(conflictOptions?.setWhere)
expect(setWhere).toContain('json_typeof')
expect(setWhere).not.toContain('jsonb_typeof')
expect(setWhere).toContain('IS DISTINCT FROM')
expect(setWhere).toContain('in-progress')
})
Expand Down Expand Up @@ -229,7 +231,8 @@ describe('IdempotencyService in-progress deadlines', () => {
service.executeWithIdempotency('provider', 'delivery-retry-db', vi.fn())
).resolves.toBe('new-owner-result')

const condition = dbChainMockFns.where.mock.calls.at(-1)?.[0]
expect(JSON.stringify(condition)).toContain('retry me')
const condition = JSON.stringify(dbChainMockFns.where.mock.calls.at(-1)?.[0])
expect(condition).toContain('retry me')
expect(condition.match(/::jsonb/g)).toHaveLength(2)
})
})
4 changes: 2 additions & 2 deletions apps/sim/lib/core/idempotency/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class IdempotencyService {
const expiredBefore = new Date(now.getTime() - this.config.ttlSeconds * 1000)
const inProgressClaimExpired = sql`COALESCE(
CASE
WHEN jsonb_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
WHEN json_typeof(${idempotencyKey.result} -> 'inProgressExpiresAt') = 'number'
THEN (${idempotencyKey.result} ->> 'inProgressExpiresAt')::double precision
END,
EXTRACT(EPOCH FROM ${idempotencyKey.createdAt}) * 1000 + ${this.config.inProgressTtlSeconds * 1000}
Expand Down Expand Up @@ -548,7 +548,7 @@ export class IdempotencyService {
: fence?.observedResult
? and(
eq(idempotencyKey.key, normalizedKey),
sql`${idempotencyKey.result} = ${JSON.stringify(fence.observedResult)}::jsonb`
sql`${idempotencyKey.result}::jsonb = ${JSON.stringify(fence.observedResult)}::jsonb`
)
: eq(idempotencyKey.key, normalizedKey)
const deleted = await db
Expand Down
Loading