Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Last active May 14, 2023 12:29
Show Gist options
  • Save christopherbauer/8aec5573626681f02f61c1398fde37c5 to your computer and use it in GitHub Desktop.
Save christopherbauer/8aec5573626681f02f61c1398fde37c5 to your computer and use it in GitHub Desktop.
import { User } from "./DataAccessLayer";
import { LogCall } from "./logCall";
import { Retry } from "./retry";
export type Action = "Click" | "Submit" | "Redirect";
function randomIntInclusive(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
export class MetricTracking {
/**
* This method attempts to mark a user action in the metric tracking service. It retries 3x over the course of 5 seconds
* @param user The user who performed the action
* @param action The action that was performed
*/
@Retry(3, 5000 / 3)
@LogCall
trackMetric(user: User, action: Action): void {
const roll = randomIntInclusive(1, 3);
if (roll === 3) {
console.log("Failure occurred!");
throw new Error("Service unavailable");
}
console.log("Success");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment