require "securerandom"
class RedisMutex
class LockError < StandardError; end
UNLOCK_SCRIPT = <<~LUA.freeze
package pricecache
import (
"context"
"sync"
class PresenceRegistry
TTL = 30 # seconds a user counts as present without a heartbeat
def initialize(room_id, redis: REDIS)
@room_id = room_id
@redis = redis
<?php
namespace App\Jobs;
use App\Models\Invoice;
use App\Services\StripeGateway;
<?php
namespace App\Observers;
use App\Models\Product;
use App\Jobs\WarmRelatedProductsCache;
<?php
declare(strict_types=1);
namespace App\Security;
-- KEYS[1] = bucket key
-- ARGV[1] = capacity, ARGV[2] = refill_rate (tokens/sec)
-- ARGV[3] = now_ms, ARGV[4] = requested tokens
local capacity = tonumber(ARGV[1])
local refill_rate = tonumber(ARGV[2])
local now_ms = tonumber(ARGV[3])
class SlidingWindowLimiter
Result = Struct.new(:allowed, :count, :limit, :window_ms, keyword_init: true)
SCRIPT = <<~LUA.freeze
local key = KEYS[1]
local now = tonumber(ARGV[1])
import time
from collections import namedtuple
from sqlalchemy import text
CheckResult = namedtuple("CheckResult", ["name", "healthy", "latency_ms", "detail"])
class DebouncedReindexJob
include Sidekiq::Job
sidekiq_options queue: :indexing, retry: 5
DEBOUNCE_DELAY = 5 # seconds
package mailer
import (
"crypto/sha256"
"encoding/hex"
"strings"
package health
import (
"context"
"sync"
"time"