class SyncContactJob < ApplicationJob
queue_as :external
BACKOFF = ->(executions) do
(2**executions) + rand(0.0..1.0) # exponential + jitter, in seconds
end
class User < ApplicationRecord
has_one_attached :avatar do |attachable|
attachable.variant :thumb,
resize_to_limit: [256, 256],
convert: :webp,
saver: { quality: 80 }
class PopularPostsQuery
def initialize(relation = Post.all)
@relation = relation
end
def call(timeframe: 7.days, min_views: 100, limit: 20)
module Authorizable
extend ActiveSupport::Concern
class NotAuthorized < StandardError; end
included do
// app/javascript/controllers/dropdown_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["menu"]
<div class="copy-field"
data-controller="clipboard"
data-clipboard-content-value="<%= content %>"
data-clipboard-success-value="Copied!">
<input type="text"
class TrendingPostsService
CACHE_KEY = 'trending_posts:v1'.freeze
CACHE_TTL = 15.minutes
def self.call(limit: 10)
Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_TTL) do
module TurboResponder
extend ActiveSupport::Concern
private
def respond_with_turbo(resource, on_success:, partial:, notice: nil)
class CreateAuditLogs < ActiveRecord::Migration[6.1]
def change
create_table :audit_logs do |t|
t.references :user, null: true, foreign_key: true
t.string :action, null: false
t.string :resource_type
class ProcessPaymentWorker
include Sidekiq::Worker
sidekiq_options queue: :critical, retry: 10
sidekiq_retry_in do |count, exception|
<%= turbo_stream_from [current_member, :notifications] %>
<div id="notification_badge">
<%= render 'notifications/badge', count: current_member.notifications.unread.count %>
</div>
class JwtService
ACCESS_TOKEN_LIFETIME = 15.minutes
REFRESH_TOKEN_LIFETIME = 7.days
SECRET = Rails.application.credentials.jwt_secret
def self.encode_access_token(user_id)