Skip to content

Commit 91f067f

Browse files
authored
feat: recheck pin status on GET /pins/:req-id (#2214)
When using kubo to `ipfs remote pin add` we get a GET request every second checking for an update to the pin status. Here we use that as a trigger to ask pickup for a status update. This will be handled by a lambda invocation and a single item db read, and will be pretty low impact. In return we will be able to inform the user as soon as their pin is complete rather than having to wait up to an hour for an async pin update job to complete. fixes #2213 License: MIT Signed-off-by: Oli Evans <oli@protocol.ai>
1 parent 6f06ca7 commit 91f067f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

packages/api/src/pins.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ export async function pinGet (request, env, ctx) {
144144
throw new PSAErrorResourceNotFound()
145145
}
146146

147+
/** @type {(() => Promise<any>)[]} */
148+
const tasks = []
149+
150+
const inProgress = pinRequest.pins.filter((p) => p.status === 'PinQueued' || p.status === 'Pinning')
151+
if (inProgress.length > 0) {
152+
tasks.push(
153+
waitAndUpdateOkPins.bind(
154+
null,
155+
pinRequest.contentCid,
156+
env.cluster,
157+
env.db)
158+
)
159+
}
160+
161+
if (ctx.waitUntil) {
162+
tasks.forEach(t => ctx.waitUntil(t()))
163+
}
164+
147165
/** @type { PsaPinStatusResponse } */
148166
return new JSONResponse(toPinStatusResponse(pinRequest))
149167
}

0 commit comments

Comments
 (0)