Andrew French

1608678960

A Simple Retry/Wait Tool for Deno

retry

A simple retry/wait tool for deno. Can re-call a function until a sucess, or bind a timeout to a function

How to:

  • to retry something:

    const result = await retry(()=> {/* do something */}, {delay:100,maxTry:5})
    
  • to retry something async :

    const result = await retryAsync(async ()=> {/* do something */}, {delay:100,maxTry:5})
    
  • Need to call a function at multiple place with same retryOptions ? Use decorators:

    const fn = (title: string, count:number) => return `${count}. ${title}`; 
    const decoratedFn = retryDecorator(fn, { delay:100, maxTry:5 });
    const title1 = await decoratedFn("Intro", 1);
    const title2 = await decoratedFn("A chapter", 2);
    
    const fn = async (name: string): Promise<any> => { /* something async */ }; 
    const decoratedFn = retryAsyncDecorator(fn, {delay:100,maxTry:5});
    const result1 = await decoratedFn("John");
    const result2 = await decoratedFn("Doe");
    
  • to set a timeout:

    try {
      const result = await waitUntil(async ()=> {/* do something */}, 10000);
    } catch (err) {
      if (isTimeoutError(error)) {
        // fn does not complete within 10 seconds
      } else {
        // fn throws an exception
      }
    }
    
  • to set a timeout on something async :

    try {
      const result = await waitUntilAsync(async ()=> {/* do something */}, 10000);
    } catch (err) {
      if (isTimeoutError(error)) {
        // fn does not complete within 10 seconds
      } else {
        // fn throws an exception
      }
    }
    
  • Need to call a function at multiple place with same durations ? Use decorators:

    const fn = (title: string, count:number) => /* a long task */; 
    const decoratedFn = waitUntilDecorator(fn, { delay:100, maxTry:5 });
    const title1 = await decoratedFn("Intro", 1);
    const title2 = await decoratedFn("A chapter", 2);
    
    const fn = async (name: string): Promise<any> => { /* a long task */ }; 
    const decoratedFn = waitUntilAsyncDecorator(fn, {delay:100,maxTry:5});
    const result1 = await decoratedFn("John");
    const result2 = await decoratedFn("Doe");
    

API

Retry familly

  • retry<T>(fn<T>, retryOptions?): call repeteadly fn until fn does not throw an exception. Stop after retryOptions.maxTry count. Between each call wait retryOptions.delay milliseconds. if stop to call fn after retryOptions.maxTry, throws fn execption, otherwise returns fn return value.

  • retryAsync<T>(fn<T>, retryOptions?): same as retry, except fn is an asynchronous function.

  • retryOptions:

    • maxTry maximum calls to fn.
    • delay: delay between each call (in milliseconds). When retryOptions is not provided, the default one is applyed. The default retry option is
      delay: 250,  // call fn every 250 ms during one minute 
      maxTry: 4 * 60, 
    
  • setDefaultRetryOptions(retryOptions: Partial<RetryOptions>): change the default retryOptions, or only the default maxTry or only the default delay). It always returns the full default retryOptions.

  • getDefaultRetryOptions(): returns the current default retry options.

  • retryAsyncDecorator(fn: T, retryOptions?: RetryOptions) and retryDecorator(fn: T, retryOptions?: RetryOptions): decorators that return a function with same signature than the given function. On decorated call, fn is called repeteadly it does not throw an exception or until retryOptions.maxTry.

Wait familly

  • waitUntil<T>(fn<T>, duration?, error?): waitUntil call asynchronously fn once. If fn complete within the duration (express in miliseconds), waitUntil returns the fn result. Otherwhise it thows the given error (if any) or a TimeoutError exception.
  • waitUntilAsync<T>(fn<T>, duration?, error?): same as waitUntil, except fn is an asynchronous function.
  • TimeoutError: an error thrown by waitUntil and waitUntilAsync. It comes with a isTimeoutError type guard:
  if (isTimeoutError(error)) {
    // fn does not complete within 10 seconds
  }

In case of timeout fn is still executing. It is advise to add a mean to abort it.

  • When duration is not provided, the default one is applyed. The default default is 60000ms.
  • setDefaultDuration(duration: number): change the default duration.
  • getDefaultDuration(): returns the current default duration.
  • waitUntilAsyncDecorator(fn: T, duration?: number, error?: Error) and waitUntilDecorator(fn: T, duration?: number, error?: Error): decorators that return a function with same signature than the given function. On decorated call, fn is called bounded to the duration.

Compatilibity

Use std 0.81.0 (deno 1.6.1) but is is aslo tested with lates deno 1.3.x, 1.4.x and 1.5.x.

Download Details:

Author: franckLdx

Source Code: https://github.com/franckLdx/retry

#deno #nodejs #javascript #node

What is GEEK

Buddha Community

A Simple Retry/Wait Tool for Deno

Build A Simple CLI Tool using Deno

What is Deno?

Deno is a JavaScript/TypeScript runtime with secure defaults and great developer experience. It’s built on V8, Rust, and Tokio. I suggest you watch these talks by Ryan: He talks about his mistakes with Nodejs here and a more in-depth look into deno here

Features
  • Secure by default. No file, network, or environment access (unless explicitly enabled).
  • Supports TypeScript out of the box.
  • Ships a single executable (deno).
  • Has built-in utilities like a dependency inspector (deno info) and a code formatter (deno fmt).
  • Has a set of reviewed (audited) standard modules that are guaranteed to work with Deno. Scripts can be bundled into a single JavaScript file.

Lets Build Something!!!

In this article, we’re going to build a simple cli tool to demonstrate some of the features of deno. Our cli will be interacting with a COVID API to fetch live data.

Requirement: make sure you have deno installed. If you don’t, refer to this link. It’s pretty straightforward.

Deno has the entry file mod.ts so we will follow the same in this article if you are following this article along with the coding you can create a folder named covid-cli, inside that folder you can create a file called mod.ts and copy the below code there.

const { args } = Deno;
import { parse } from "https://deno.land/std/flags/mod.ts";

console.dir(parse(args));

Here the parse(args, options = {}); contains two parameters where args is an Array and options is an object, let try to run the above code using this cmd.

deno run mod.ts arg1 -f hello --flag World --booleanFlag

#deno #cli tool #tool

Andrew French

1608678960

A Simple Retry/Wait Tool for Deno

retry

A simple retry/wait tool for deno. Can re-call a function until a sucess, or bind a timeout to a function

How to:

  • to retry something:

    const result = await retry(()=> {/* do something */}, {delay:100,maxTry:5})
    
  • to retry something async :

    const result = await retryAsync(async ()=> {/* do something */}, {delay:100,maxTry:5})
    
  • Need to call a function at multiple place with same retryOptions ? Use decorators:

    const fn = (title: string, count:number) => return `${count}. ${title}`; 
    const decoratedFn = retryDecorator(fn, { delay:100, maxTry:5 });
    const title1 = await decoratedFn("Intro", 1);
    const title2 = await decoratedFn("A chapter", 2);
    
    const fn = async (name: string): Promise<any> => { /* something async */ }; 
    const decoratedFn = retryAsyncDecorator(fn, {delay:100,maxTry:5});
    const result1 = await decoratedFn("John");
    const result2 = await decoratedFn("Doe");
    
  • to set a timeout:

    try {
      const result = await waitUntil(async ()=> {/* do something */}, 10000);
    } catch (err) {
      if (isTimeoutError(error)) {
        // fn does not complete within 10 seconds
      } else {
        // fn throws an exception
      }
    }
    
  • to set a timeout on something async :

    try {
      const result = await waitUntilAsync(async ()=> {/* do something */}, 10000);
    } catch (err) {
      if (isTimeoutError(error)) {
        // fn does not complete within 10 seconds
      } else {
        // fn throws an exception
      }
    }
    
  • Need to call a function at multiple place with same durations ? Use decorators:

    const fn = (title: string, count:number) => /* a long task */; 
    const decoratedFn = waitUntilDecorator(fn, { delay:100, maxTry:5 });
    const title1 = await decoratedFn("Intro", 1);
    const title2 = await decoratedFn("A chapter", 2);
    
    const fn = async (name: string): Promise<any> => { /* a long task */ }; 
    const decoratedFn = waitUntilAsyncDecorator(fn, {delay:100,maxTry:5});
    const result1 = await decoratedFn("John");
    const result2 = await decoratedFn("Doe");
    

API

Retry familly

  • retry<T>(fn<T>, retryOptions?): call repeteadly fn until fn does not throw an exception. Stop after retryOptions.maxTry count. Between each call wait retryOptions.delay milliseconds. if stop to call fn after retryOptions.maxTry, throws fn execption, otherwise returns fn return value.

  • retryAsync<T>(fn<T>, retryOptions?): same as retry, except fn is an asynchronous function.

  • retryOptions:

    • maxTry maximum calls to fn.
    • delay: delay between each call (in milliseconds). When retryOptions is not provided, the default one is applyed. The default retry option is
      delay: 250,  // call fn every 250 ms during one minute 
      maxTry: 4 * 60, 
    
  • setDefaultRetryOptions(retryOptions: Partial<RetryOptions>): change the default retryOptions, or only the default maxTry or only the default delay). It always returns the full default retryOptions.

  • getDefaultRetryOptions(): returns the current default retry options.

  • retryAsyncDecorator(fn: T, retryOptions?: RetryOptions) and retryDecorator(fn: T, retryOptions?: RetryOptions): decorators that return a function with same signature than the given function. On decorated call, fn is called repeteadly it does not throw an exception or until retryOptions.maxTry.

Wait familly

  • waitUntil<T>(fn<T>, duration?, error?): waitUntil call asynchronously fn once. If fn complete within the duration (express in miliseconds), waitUntil returns the fn result. Otherwhise it thows the given error (if any) or a TimeoutError exception.
  • waitUntilAsync<T>(fn<T>, duration?, error?): same as waitUntil, except fn is an asynchronous function.
  • TimeoutError: an error thrown by waitUntil and waitUntilAsync. It comes with a isTimeoutError type guard:
  if (isTimeoutError(error)) {
    // fn does not complete within 10 seconds
  }

In case of timeout fn is still executing. It is advise to add a mean to abort it.

  • When duration is not provided, the default one is applyed. The default default is 60000ms.
  • setDefaultDuration(duration: number): change the default duration.
  • getDefaultDuration(): returns the current default duration.
  • waitUntilAsyncDecorator(fn: T, duration?: number, error?: Error) and waitUntilDecorator(fn: T, duration?: number, error?: Error): decorators that return a function with same signature than the given function. On decorated call, fn is called bounded to the duration.

Compatilibity

Use std 0.81.0 (deno 1.6.1) but is is aslo tested with lates deno 1.3.x, 1.4.x and 1.5.x.

Download Details:

Author: franckLdx

Source Code: https://github.com/franckLdx/retry

#deno #nodejs #javascript #node

50+ Useful DevOps Tools

The article comprises both very well established tools for those who are new to the DevOps methodology.

What Is DevOps?

The DevOps methodology, a software and team management approach defined by the portmanteau of Development and Operations, was first coined in 2009 and has since become a buzzword concept in the IT field.

DevOps has come to mean many things to each individual who uses the term as DevOps is not a singularly defined standard, software, or process but more of a culture. Gartner defines DevOps as:

“DevOps represents a change in IT culture, focusing on rapid IT service delivery through the adoption of agile, lean practices in the context of a system-oriented approach. DevOps emphasizes people (and culture), and seeks to improve collaboration between operations and development teams. DevOps implementations utilize technology — especially automation tools that can leverage an increasingly programmable and dynamic infrastructure from a life cycle perspective.”

As you can see from the above definition, DevOps is a multi-faceted approach to the Software Development Life Cycle (SDLC), but its main underlying strength is how it leverages technology and software to streamline this process. So with the right approach to DevOps, notably adopting its philosophies of co-operation and implementing the right tools, your business can increase deployment frequency by a factor of 30 and lead times by a factor of 8000 over traditional methods, according to a CapGemini survey.

The Right Tools for the Job

This list is designed to be as comprehensive as possible. The article comprises both very well established tools for those who are new to the DevOps methodology and those tools that are more recent releases to the market — either way, there is bound to be a tool on here that can be an asset for you and your business. For those who already live and breathe DevOps, we hope you find something that will assist you in your growing enterprise.

With such a litany of tools to choose from, there is no “right” answer to what tools you should adopt. No single tool will cover all your needs and will be deployed across a variety of development and Operational teams, so let’s break down what you need to consider before choosing what tool might work for you.

  • Plan and collaborate: Before you even begin the SDLC, your business needs to have a cohesive idea of what tools they’ll need to implement across your teams. There are even DevOps tools that can assist you with this first crucial step.
  • Build: Here you want tools that create identically provisioned environments. The last you need is to hear “But it works for me on my computer”
  • Automation: This has quickly become a given in DevOps, but automation will always drastically increase production over manual methods.
  • Continuous Integration: Tools need to provide constant and immediate feedback, several times a day but not all integrations are implemented equally, will the tool you select be right for the job?
  • Deployment: Deployments need to be kept predictable, smooth, and reliable with minimal risks, automation will also play a big part in this process.

With all that in mind, I hope this selection of tools will aid you as your business continues to expand into the DevOps lifestyle.

Tools Categories List:

Infrastructure As Code

Continuous Integration and Delivery

Development Automation

Usability Testing

Database and Big Data

Monitoring

Testing

Security

Helpful CLI Tools

Development

Visualization

Infrastructure As Code

#AWSCloudFormation

1. AWS CloudFormation

AWS CloudFormation is an absolute must if you are currently working, or planning to work, in the AWS Cloud. CloudFormation allows you to model your AWS infrastructure and provision all your AWS resources swiftly and easily. All of this is done within a JSON or YAML template file and the service comes with a variety of automation features ensuring your deployments will be predictable, reliable, and manageable.

Link: https://aws.amazon.com/cloudformation/

2. Azure Resource Manager

Azure Resource Manager (ARM) is Microsoft’s answer to an all-encompassing IAC tool. With its ARM templates, described within JSON files, Azure Resource Manager will provision your infrastructure, handle dependencies, and declare multiple resources via a single template.

Link: https://azure.microsoft.com/en-us/features/resource-manager/

#Google Cloud Deployment Manager

3. Google Cloud Deployment Manager

Much like the tools mentioned above, Google Cloud Deployment Manager is Google’s IAC tool for the Google Cloud Platform. This tool utilizes YAML for its config files and JINJA2 or PYTHON for its templates. Some of its notable features are synchronistic deployment and ‘preview’, allowing you an overhead view of changes before they are committed.

Link: https://cloud.google.com/deployment-manager/

4. Terraform

Terraform is brought to you by HashiCorp, the makers of Vault and Nomad. Terraform is vastly different from the above-mentioned tools in that it is not restricted to a specific cloud environment, this comes with increased benefits for tackling complex distributed applications without being tied to a single platform. And much like Google Cloud Deployment Manager, Terraform also has a preview feature.

Link: https://www.terraform.io/

#Chef

5. Chef

Chef is an ideal choice for those who favor CI/CD. At its heart, Chef utilizes self-described recipes, templates, and cookbooks; a collection of ready-made templates. Cookbooks allow for consistent configuration even as your infrastructure rapidly scales. All of this is wrapped up in a beautiful Ruby-based DSL pie.

Link: https://www.chef.io/products/chef-infra/

#Ansible

#tools #devops #devops 2020 #tech tools #tool selection #tool comparison

Sunny  Kunde

Sunny Kunde

1597848060

Top 12 Most Used Tools By Developers In 2020

rameworks and libraries can be said as the fundamental building blocks when developers build software or applications. These tools help in opting out the repetitive tasks as well as reduce the amount of code that the developers need to write for a particular software.

Recently, the Stack Overflow Developer Survey 2020 surveyed nearly 65,000 developers, where they voted their go-to tools and libraries. Here, we list down the top 12 frameworks and libraries from the survey that are most used by developers around the globe in 2020.

(The libraries are listed according to their number of Stars in GitHub)

1| TensorFlow

**GitHub Stars: **147k

Rank: 5

**About: **Originally developed by researchers of Google Brain team, TensorFlow is an end-to-end open-source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries, and community resources that lets researchers push the state-of-the-art research in ML. It allows developers to easily build and deploy ML-powered applications.

Know more here.

2| Flutter

**GitHub Stars: **98.3k

**Rank: **9

About: Created by Google, Flutter is a free and open-source software development kit (SDK) which enables fast user experiences for mobile, web and desktop from a single codebase. The SDK works with existing code and is used by developers and organisations around the world.


#opinions #developer tools #frameworks #java tools #libraries #most used tools by developers #python tools

Marcelle  Smith

Marcelle Smith

1598437740

A Simple Guide to API Development Tools

APIs can be as simple as 1 endpoint for use by 100s of users or as complex as the AWS APIs with 1000s of endpoints and 100s of thousands of users. Building them can mean spending a couple of hours using a low-code platform or months of work using a multitude of tools. Hosting them can be as simple as using one platform that does everything we need or as complex as setting up and managing ingress control, security, caching, failover, metrics, scaling etc.

What they all have in common are three basic steps to go from nothing to a running API.

Each of these steps has its own set of tools. Here are some I’ve used and popular alternatives.

Design

REST is the most popular API interface and has the best tooling. Our design output for REST services always includes an OpenAPI specification. The specification language can be tricky to get right in JSON (how many curly brackets?) or YAML (how many spaces?) so a good editor saves a lot of time.

Four popular ones are:

I’ve only used Swagger and Postman but both Insomnia and Stoplight look interesting. All of them offer additional functionality like documentation, testing and collaboration so are much more than just specification generators.

#api #apis #api-development #restful-api #rest-api #development-tools #app-development-tools #developer-tools