From 61e9bfc505373e64c3c6aa4867c241b3cc985f1b Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 7 Mar 2021 10:29:37 +0100 Subject: [PATCH] Add retries and retries_delay options --- source/app/action/index.mjs | 18 +++++++++++++++++- source/plugins/core/README.md | 15 +++++++++++++++ source/plugins/core/metadata.yml | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index f88db521..50815639 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -57,6 +57,7 @@ "plugins.errors.fatal":die, "committer.token":_token, "committer.branch":_branch, "use.prebuilt.image":_image, + retries, "retries.delay":retries_delay, ...config } = metadata.plugins.core.inputs.action({core}) const q = {...query, ...(_repo ? {repo:_repo} : null), template} @@ -202,7 +203,22 @@ //Render metrics info.break() info.section("Rendering") - const {rendered} = await metrics({login:user, q}, {graphql, rest, plugins, conf, die, verify, convert}, {Plugins, Templates}) + let rendered = null, error = null + for (let attempt = 0; attempt < retries; attempt++) { + try { + console.debug(`::group::Attempt ${attempt}/${retries}`) + rendered = (await metrics({login:user, q}, {graphql, rest, plugins, conf, die, verify, convert}, {Plugins, Templates})).rendered + console.debug("::endgroup::") + break + } + catch (_error) { + error = _error + console.debug("::endgroup::") + console.debug(`::warning::rendering failed (${error.message})`) + } + } + if (!rendered) + throw error ?? new Error(`Could not render metrics`) info("Status", "complete") //Commit metrics diff --git a/source/plugins/core/README.md b/source/plugins/core/README.md index b603fff2..7b8a0203 100644 --- a/source/plugins/core/README.md +++ b/source/plugins/core/README.md @@ -102,6 +102,21 @@ Specify a single value to apply it to both height and with, and two values to us config_padding: 6%, 10% # 6% width padding, 10% height padding ``` +### ♻️ Retrying automatically failed rendering + +Rendering is subject to external factors and can fail from time to time. +It is possible to mitigate this issue using `retries` and `retries_delay` options to automatically retry later metrics rendering and avoid workflow fails. + +#### ℹ️ Examples workflows + +```yaml +- uses: lowlighter/metrics@latest + with: + # ... other options + retries: 3 + retries_delay: 300 +``` + ### 💱 Convert output to PNG/JPEG It is possible to convert output from SVG to PNG or JPEG images by using `config_output` option. diff --git a/source/plugins/core/metadata.yml b/source/plugins/core/metadata.yml index 2655dbb5..81aaa0ff 100644 --- a/source/plugins/core/metadata.yml +++ b/source/plugins/core/metadata.yml @@ -138,6 +138,22 @@ inputs: - png # Does not support animations - jpeg # Does not support animations and transparency + # Number of retries in case rendering fail + retries: + description: Number of retries + type: number + default: 3 + min: 1 + max: 10 + + # Time to wait (in seconds) before each retry + retries_delay: + description: Time to wait (in seconds) before each retry + type: number + default: 300 + min: 0 + max: 3600 + # ==================================================================================== # Options below are mostly used for testing