Skip to content

Instantly share code, notes, and snippets.

View willgarcia's full-sized avatar
🌴

William Garcia willgarcia

🌴
  • Brisbane, Australia
View GitHub Profile

API Retry Patterns

Collection of Python implementations for handling API calls with token refresh retry logic.

Problem

When processing multiple items through an API, authentication tokens can expire mid-process. This requires:

  • Looping through items
  • Retrying API calls when tokens expire
  • Refreshing tokens between retries
import boto3
import os
# Replace these with your AWS credentials or set them as environment variables
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
# Create AWS clients
ec2_client = boto3.client('ec2', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
elb_v2_client = boto3.client('elbv2', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
@willgarcia
willgarcia / Dockerfile
Created January 25, 2024 21:28
Example docker network beginner
# Use an official Node.js runtime as a parent image
FROM node:14
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install app dependencies
apiVersion: org.eclipse.che/v2
kind: CheCluster
metadata:
name: devspaces
namespace: openshift-devspaces
annotations:
argocd.argoproj.io/sync-wave: "20"
spec:
components:
cheServer:
#!/bin/bash
URLS_TO_VALIDATE="https://registry.redhat.io
https://quay.io
https://cdn01.quay.io
https://cdn02.quay.io
https://cdn03.quay.io
https://sso.redhat.com
http://sso.redhat.com
https://quay-registry.s3.amazonaws.com
#!/bin/bash
oc delete subscription ecr-secret-operator \
--namespace ecr-secret-operator
oc delete subscription ecr-secret-operator \
--namespace ecr-secret-operator
oc delete clusterserviceversion ecr-secret-operator.v0.3.2 \
--namespace ecr-secret-operator
oc delete project ecr-secret-operator
oc delete project my-app

####!/bin/bash

Set Variables

Set working directory (pwd for now)

export TMP_DIR="$(pwd)"

Set Prefix for AWS resources

export SUFFIX="-jrfuller"

Yarn - Lerna

Questions:

  • Is it easier to keep the same version in all shared lib packages?
  • If lerna publish happens only in master/CI, how do we update dependencies in feature branches? should we push to master first, then update?

Option 1: no yarn lock file

  • All @TUO package dependencies are marked as version ^1.0.0 in their packages/*/package.json
@willgarcia
willgarcia / ticker.go
Created March 29, 2021 11:33 — forked from MortenDHansen/ticker.go
GoLang ticker - every second for ... time
package main
import "time"
import "fmt"
func main() {
tickerChannel := time.NewTicker(1 * time.Second)
go func() {
for {
select {
@willgarcia
willgarcia / deleteOldSnapshots.sh
Created September 15, 2020 11:52 — forked from yufufi/deleteOldSnapshots.sh
Scripts to manage AKS Disk snapshots
# set the expiry to a month ago
expirydate=$(date -d'-1 month' +%s)
# I can use az -o table with cut -d driectly
for snapshot in $(az snapshot list -g $resourceGroup | jq -r '.[] | [.id, .timeCreated[:10], .name] | join("#")')
do
snapshotId=$(echo $snapshot | cut -f1 -d "#")
snapshotDate=$(echo $snapshot | cut -f2 -d "#" | xargs -I{} date -d {} +%s)
snapshotName=$(echo $snapshot | cut -f3 -d "#")