tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
fix syncing leaflet published post bsky likes
awarm.space
3 weeks ago
6c70cf43
f758cd17
+13
-5
1 changed file
expand all
collapse all
unified
split
app
api
inngest
functions
sync_document_metadata.ts
+13
-5
app/api/inngest/functions/sync_document_metadata.ts
···
3
3
import { AtpAgent, AtUri } from "@atproto/api";
4
4
import { idResolver } from "app/(home-pages)/reader/idResolver";
5
5
6
6
-
const TOTAL_ITERATIONS = 144; // 36 hours at 15-minute intervals
6
6
+
// 1m, 2m, 4m, 8m, 16m, 32m, 1h, 2h, 4h, 8h, 8h, 8h (~37h total)
7
7
+
const SLEEP_INTERVALS = [
8
8
+
"1m", "2m", "4m", "8m", "16m", "32m", "1h", "2h", "4h", "8h", "8h", "8h",
9
9
+
];
7
10
8
11
export const sync_document_metadata = inngest.createFunction(
9
12
{
10
13
id: "sync_document_metadata",
11
11
-
idempotency: "event.data.document_uri",
14
14
+
debounce: {
15
15
+
key: "event.data.document_uri",
16
16
+
period: "60s",
17
17
+
timeout: "3m",
18
18
+
},
19
19
+
concurrency: [{ key: "event.data.document_uri", limit: 1 }],
12
20
},
13
21
{ event: "appview/sync-document-metadata" },
14
22
async ({ event, step }) => {
···
61
69
62
70
let likeCount = await step.run("sync-0", fetchAndUpdate);
63
71
64
64
-
for (let i = 1; i < TOTAL_ITERATIONS; i++) {
65
65
-
await step.sleep(`wait-${i}`, "15m");
66
66
-
likeCount = await step.run(`sync-${i}`, fetchAndUpdate);
72
72
+
for (let i = 0; i < SLEEP_INTERVALS.length; i++) {
73
73
+
await step.sleep(`wait-${i + 1}`, SLEEP_INTERVALS[i]);
74
74
+
likeCount = await step.run(`sync-${i + 1}`, fetchAndUpdate);
67
75
}
68
76
69
77
return { likeCount, handle: handleResult.handle };