{"id":20170209,"url":"https://github.com/fabrix-app/spool-retry","last_synced_at":"2025-03-03T04:15:54.731Z","repository":{"id":47907784,"uuid":"238512711","full_name":"fabrix-app/spool-retry","owner":"fabrix-app","description":"Spool: Easily Retry operations with Fabrix Apps","archived":false,"fork":false,"pushed_at":"2023-01-24T01:18:56.000Z","size":591,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T15:27:02.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabrix-app.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-05T17:50:16.000Z","updated_at":"2020-07-26T16:53:20.000Z","dependencies_parsed_at":"2023-01-31T14:35:31.838Z","dependency_job_id":null,"html_url":"https://github.com/fabrix-app/spool-retry","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabrix-app","download_url":"https://codeload.github.com/fabrix-app/spool-retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241605820,"owners_count":19989612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T01:17:41.232Z","updated_at":"2025-03-03T04:15:54.711Z","avatar_url":"https://github.com/fabrix-app.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spool-retry\n\n[![Gitter][gitter-image]][gitter-url]\n[![NPM version][npm-image]][npm-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coverage-image]][coverage-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Follow @FabrixApp on Twitter][twitter-image]][twitter-url]\n\n:package: retry Spool\n\nA Spool to make it easy to use [Retries](https://www.npmjs.com/package/promise-retry) with Fabrix\n\n## Install\n```sh\n$ npm install --save @fabrix/spool-retry\n```\n\n## Configure\n\n```ts\n// config/main.ts\nimport { RetrySpool } from '@fabrix/spool-retry'\nexport const main = {\n  spools: [\n    // ... other spools\n    RetrySpool\n  ]\n}\n```\n\n## Configuration\n\n```ts\n// config/retry.ts\nexport const retry = {\n  // retries: The maximum amount of times to retry the operation. Default is 10.\n  retries: null, // 10,\n  // factor: The exponential factor to use. Default is 2.\n  factor: null, // 2,\n  // minTimeout: The number of milliseconds before starting the first retry. Default is 1000.\n  minTimeout: null, // 1000,\n  // maxTimeout: The maximum number of milliseconds between two retries. Default is Infinity.\n  maxTimeout: null,\n  // randomize: Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.\n  randomize: false\n}\n```\n\nFor more information about store (type and configuration) please see the retry documentation.\n\n## Usage\nFor the best results, create a Base Class and override or extend the default methods. \n```ts\n  import { RetryManager } from '@fabrix/spool-retry'\n  \n  export class MyRetry extends RetryManager {\n    myFunc(data, opts) {\n      const func = this.app.services.somePromiseService(data, opts)\n      return this.attempt(func)\n        .catch(err =\u003e {\n           this.app.log.error(err)\n           return Promise.reject(err)\n        })\n    }\n\n    cancelByNameAt5 (name, number) {\n      if (number === 5) {\n        this.cancelled_retries.add(name)\n      }\n      return\n    }\n\n    // We are overriding the AfterEachFailure function to have it cancel softly at 5 tries\n    afterEachFailure(name, params, retry, number, err) {\n      this.cancelByNameAt5(name, number)\n      return retry(err)\n    }\n  }\n```\n\nOr simply\n```ts\n this.app.retries.MyRetry.attempt(func, params)\n```\n\n[npm-image]: https://img.shields.io/npm/v/@fabrix/spool-retry.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@fabrix/spool-retry\n[ci-image]: https://img.shields.io/circleci/project/github/fabrix-app/spool-retry/master.svg\n[ci-url]: https://circleci.com/gh/fabrix-app/spool-retry/tree/master\n[daviddm-image]: http://img.shields.io/david/fabrix-app/spool-retry.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/fabrix-app/spool-retry\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/fabrix-app/fabrix\n[twitter-image]: https://img.shields.io/twitter/follow/FabrixApp.svg?style=social\n[twitter-url]: https://twitter.com/FabrixApp\n[coverage-image]: https://img.shields.io/codeclimate/coverage/github/fabrix-app/spool-retry.svg?style=flat-square\n[coverage-url]: https://codeclimate.com/github/fabrix-app/spool-retry/coverage\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabrix-app%2Fspool-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-retry/lists"}