Skip to content

Commit

Permalink
Merge pull request #325 from vim-jp-radio/featrue/retry-tweet
Browse files Browse the repository at this point in the history
retry get tweet
  • Loading branch information
ryoppippi authored Oct 19, 2024
2 parents 7958c58 + c897253 commit c8235c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@antfu/eslint-config": "^3.0.0",
"@iconify-json/ph": "^1.2.0",
"@ryoppippi/vite-plugin-cloudflare-redirect": "npm:@jsr/ryoppippi__vite-plugin-cloudflare-redirect@^1.0.2",
"@std/async": "npm:@jsr/std__async@^1.0.6",
"@std/collections": "npm:@jsr/std__collections@^1.0.5",
"@sveltejs/adapter-static": "^3.0.4",
"@sveltejs/enhanced-img": "^0.3.8",
Expand All @@ -36,7 +37,6 @@
"eslint-plugin-format": "^0.1.2",
"eslint-plugin-svelte": "^2.43.0",
"favicons": "^7.2.0",
"p-retry": "^6.2.0",
"renovate": "^38.68.0",
"std-env": "^3.7.0",
"svelte": "5.0.0-next.262",
Expand Down
38 changes: 8 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import type { Tweet } from 'sveltweet';
import { LISTENERS_TWEET_IDS } from '$/lib/links';
import { retry } from '@std/async';
import { error } from '@sveltejs/kit';
import pRetry from 'p-retry';
import { getTweet } from 'sveltweet/api';

/* tweet を取得する。 */
export async function load() {
const tweets: Tweet[] = [];
for (const id of LISTENERS_TWEET_IDS) {
const tweet = await pRetry(async () => getTweet(id), { retries: 5 });
const tweet = await retry(async () => {
const _tweet = await getTweet(id);

if (_tweet == null) {
throw new Error(`Retry: Tweet not found: ${id}`);
}
return _tweet;
});
if (tweet == null) {
error(404, `Tweet not found: ${id}`);
}
Expand Down

0 comments on commit c8235c6

Please sign in to comment.