From 6e0b0cdb07e416d7ee14b7480ea907388a3d338d Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Sat, 5 Oct 2024 16:42:02 +0300 Subject: [PATCH 1/5] fix(root): edit cd cron expression wd-676 --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index cfbdb66a..2888643b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -2,7 +2,7 @@ name: Continuous Delivery on: schedule: - - cron: '0 0 * * *' + - cron: '0 12 * * *' push: branches: - main From e821e0421ffcc98e89b82435ac6076c1a0730d86 Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Sun, 6 Oct 2024 18:37:51 +0300 Subject: [PATCH 2/5] feat(shared): update setAsyncTimeout signature wd-676 --- .../whatislove-dev/src/scripts/libs/components/toast/toast.js | 2 +- .../helpers/set-async-timeout/set-async-timeout.helper.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/whatislove-dev/src/scripts/libs/components/toast/toast.js b/apps/whatislove-dev/src/scripts/libs/components/toast/toast.js index baefab0f..0a818a02 100644 --- a/apps/whatislove-dev/src/scripts/libs/components/toast/toast.js +++ b/apps/whatislove-dev/src/scripts/libs/components/toast/toast.js @@ -32,7 +32,7 @@ class Toast { toastNode.textContent = message - await setAsyncTimeout(() => {}, duration) + await setAsyncTimeout(undefined, duration) await setAsyncTimeout(() => { toastNode.textContent = `` diff --git a/packages/shared/src/libs/helpers/set-async-timeout/set-async-timeout.helper.js b/packages/shared/src/libs/helpers/set-async-timeout/set-async-timeout.helper.js index d59bb0f6..c18359a9 100644 --- a/packages/shared/src/libs/helpers/set-async-timeout/set-async-timeout.helper.js +++ b/packages/shared/src/libs/helpers/set-async-timeout/set-async-timeout.helper.js @@ -1,12 +1,12 @@ /** - * @param {(...args: unknown[]) => unknown} callback + * @param {((...args: unknown[]) => unknown) | undefined} callback * @param {number} [timeout] * @returns {Promise} */ let setAsyncTimeout = (callback, timeout = 0) => { return new Promise((resolve) => { setTimeout(() => { - callback() + callback?.() resolve() }, timeout) }) From c7f4ee432b4c850a3f7aa96cc43381689daf1335 Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Sun, 6 Oct 2024 18:40:40 +0300 Subject: [PATCH 3/5] feat(whatislove-dev): add retry functionality for api calls wd-676 --- apps/whatislove-dev/src/data/mentions.js | 6 ++- packages/shared/src/index.js | 1 + packages/shared/src/libs/helpers/helpers.js | 1 + .../helpers/retry-call/retry-call.helper.js | 45 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 packages/shared/src/libs/helpers/retry-call/retry-call.helper.js diff --git a/apps/whatislove-dev/src/data/mentions.js b/apps/whatislove-dev/src/data/mentions.js index a443ffcf..eda04ec6 100644 --- a/apps/whatislove-dev/src/data/mentions.js +++ b/apps/whatislove-dev/src/data/mentions.js @@ -1,3 +1,4 @@ +import { retryCall } from '@whatislove.dev/shared' import { parseHTML } from 'linkedom' import { default as environment } from './environment.js' @@ -270,7 +271,10 @@ let loader = async () => { let allPagesMentions = /** @type {PagesMentions} */ ({}) for (let mentionLoader of mentionLoaders) { - let fetchedPageMentions = await mentionLoader() + let fetchedPageMentions = await retryCall({ + callback: mentionLoader, + retriesCount: 3, + }) for (let [pageUrl, pageMentions] of Object.entries( fetchedPageMentions, diff --git a/packages/shared/src/index.js b/packages/shared/src/index.js index 0383216e..b060a6e6 100644 --- a/packages/shared/src/index.js +++ b/packages/shared/src/index.js @@ -6,6 +6,7 @@ export { getRandomNumber, getShuffledItems, initDebounce, + retryCall, setAsyncTimeout, } from './libs/helpers/helpers.js' export { ValuesOf } from './libs/types/types.js' diff --git a/packages/shared/src/libs/helpers/helpers.js b/packages/shared/src/libs/helpers/helpers.js index 96fcc093..beade8aa 100644 --- a/packages/shared/src/libs/helpers/helpers.js +++ b/packages/shared/src/libs/helpers/helpers.js @@ -4,4 +4,5 @@ export { getISODate } from './get-iso-date/get-iso-date.helper.js' export { getRandomNumber } from './get-random-number/get-random-number.helper.js' export { getShuffledItems } from './get-shuffled-items/get-shuffled-items.helper.js' export { initDebounce } from './init-debounce/init-debounce.helper.js' +export { retryCall } from './retry-call/retry-call.helper.js' export { setAsyncTimeout } from './set-async-timeout/set-async-timeout.helper.js' diff --git a/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js b/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js new file mode 100644 index 00000000..37dba8fb --- /dev/null +++ b/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js @@ -0,0 +1,45 @@ +import { setAsyncTimeout } from '../set-async-timeout/set-async-timeout.helper.js' + +let MINIMAL_RETRY_COUNT_FOR_CALL = /** @type {const} */ (0) +let RETRY_COUNT_DECREMENT_PER_CALL = /** @type {const} */ (1) + +/** + * @template {unknown} T + * @param {{ + * callback: (...args: unknown[]) => T | Promise + * retriesCount?: number + * delayMs?: number + * delayFactorCount?: number + * }} params + * @returns {Promise} + */ +let retryCall = async ({ + callback, + delayFactorCount = 3, + delayMs = 1000, + retriesCount = 3, +}) => { + try { + return await callback() + } catch (error) { + let hasRetries = retriesCount > MINIMAL_RETRY_COUNT_FOR_CALL + + if (!hasRetries) { + throw error + } + + await setAsyncTimeout(undefined, delayMs) + + let updatedDelayMs = delayMs * delayFactorCount + let updatedTriesCount = retriesCount - RETRY_COUNT_DECREMENT_PER_CALL + + return retryCall({ + callback, + delayFactorCount, + delayMs: updatedDelayMs, + retriesCount: updatedTriesCount, + }) + } +} + +export { retryCall } From 7d06612c132e63701e4ee93ba9ff3bf47a4a75b8 Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Sun, 6 Oct 2024 18:59:11 +0300 Subject: [PATCH 4/5] build(root): add cd action dispatch wd-676 --- .github/workflows/cd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 2888643b..bbf7fb02 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,6 +6,7 @@ on: push: branches: - main + workflow_dispatch: jobs: release: @@ -30,7 +31,7 @@ jobs: dependencies: name: Install Dependencies needs: release - if: ${{ needs.release.outputs.release_created || github.event_name == 'schedule' }} + if: ${{ needs.release.outputs.release_created || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest steps: - name: Code Checkout From 43e3a82f58ce4f70e0041a3ad2b44337af98f730 Mon Sep 17 00:00:00 2001 From: what1s1ove Date: Sun, 6 Oct 2024 18:59:59 +0300 Subject: [PATCH 5/5] build(root): add log deploy output step wd-676 --- .github/workflows/cd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index bbf7fb02..70ecb171 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -132,3 +132,6 @@ jobs: args: 'deploy --json --prod --site ${{ matrix.project }} --filter ${{ env.PACKAGE_DIR }} --dir ${{ env.PACKAGE_DIR }}/build' env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + + - name: Log Deploy Output + run: echo "${{ steps.deployment.outputs.NETLIFY_OUTPUT }}"