npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wistroni40-retry

v0.0.4

Published

Retry when failed

Downloads

2

Readme

wistroni40-retry

Install

npm i wistroni40-retry --save

Table of Contents

Quickstart

Full Example

/**
 * Kafka Producer轉接器
 */
class MyProducer extends ProducerAdapter<HighLevelProducer> {
  /**
   * @param kafkaProducer Kafka Producer
   * @param options       重拋配置
   */
  constructor(
    protected kafkaProducer: HighLevelProducer,
    protected options?: RetryOption
  ) {
    super(kafkaProducer, options);
  }

  /**
   * 發送數據
   *
   * @method public
   * @param payload  要拋送的數據 
   * @param callback 拋送後的回乎函數
   */
  public send(
    payload: ProduceRequest[],
    callback: (error: any, result: any) => void
  ): void {
    this.kafkaProducer.send(payload, (err, res) => callback(err, res));
  }
}

const myProducer = new MyProducer(PRODUCER);
const payload = { data: 100 };
myProducer.publish(payload);

Feature

  • 提供拋送者介面,實作介面中的send方法,並在送出資料時使用publish方法,即可在拋送資料失敗時,重新拋送
  • 超出失敗上限後將資料備份至特定路徑

API

ProducerAdapter

Abstract Class,拋送者轉接器

constructor

ProducerAdapter的建構值

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| producer | T | Required | undefined | 任何拋送數據的物件 options | RetryOption | Optional | Example | 重拋配置,項目可參考

Methods

publish

資料上拋方法,拋送失敗會自動嘗試重新拋送

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| payload | any | Required | undefined | 要送出的資料 callback | (error: any, result: any) => void | Required | undefined | 送出資料後的回乎函

send

Abstract Method,須實作此方法,資料上拋,但失敗不會自動重新拋送

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| payload | any | Required | undefined | 要送出的資料 callback | (error: any, result: any) => void | Required | undefined | 送出資料後的回乎函數

RetryOptions

Interface,重拋配置項目

Properties

Property | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| count | number | Optional | 3 | 送出失敗嘗試重拋的上限次數 interval | number | Optional | 5000 | 嘗試重新拋送的時間間距,單位ms backupDir | string | Optional | './backup' | 重拋失敗後的資料保存路徑

Producer

Interface,拋送者介面

Methods

send

須實作此方法,資料上拋

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| payload | any | Required | undefined | 要送出的資料 callback | (error: any, result: any) => void | Required | undefined | 送出資料後的回乎函數

RetryTemplate

Abstract Class,重拋機制範本

constructor

RetryTemplate的建構值

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| producer | Producer | Required | undefined | 拋送者 options | RetryOption | Optional | Example | 重拋配置,項目可參考

Methods

updateOptions

更新重拋配置

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| options | RetryOption | Required | Example | 重拋配置,項目可參考

retry

Abstract Method,須實作此方法,嘗試重新拋送資料

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| payload | T | Required | undefined | 要送出的資料

Retry

Class extends from RetryTemplate,重拋機制

Methods

retry

嘗試重新拋送資料

Parameter | Type | Required | Default | Description |:-----|:-----:|:-----:|:-----:|:-----| payload | T | Required | undefined | 要送出的資料