Skip to content

Instantly share code, notes, and snippets.

@swftvsn
swftvsn / retries.ts
Created Nov 11, 2019 — forked from dinvlad/retries.ts
Retries with exponential backoff and jitter for idempotent background Google Cloud Functions
View retries.ts
// one can also use Google Cloud Firestore library,
// with a slight change in semantics
import { firestore } from 'firebase-admin';
import { EventContext, runWith } from 'firebase-functions';
import { promisify } from 'util';
const eventCollection = 'function-events';
enum EventStatus {
RUNNING = 'running',
@swftvsn
swftvsn / FirebasePushIdGenerator.java
Created Mar 15, 2017
Firebase Java Push Id Generator
View FirebasePushIdGenerator.java
package firebase;
public class FirebasePushIdGenerator {
// Modeled after base64 web-safe chars, but ordered by ASCII.
private final static String PUSH_CHARS = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
// Timestamp of last push, used to prevent local collisions if you push twice in one ms.
private static long LAST_PUSH_TIME = 0L;