background-jobs

ruby
class CreateEmailDeliveries < ActiveRecord::Migration[7.1]
  def change
    create_table :email_deliveries do |t|
      t.string :dedupe_key, null: false
      t.string :mailer, null: false
      t.string :action, null: false

Transactional Email “Send Once” with Delivered Marker

rails reliability activerecord
by codesnips 4 tabs
yaml
:concurrency: 10
:queues:
  - [critical, 4]
  - [default, 2]
  - [low, 1]

Background jobs with Sidekiq and reliable queues

rails sidekiq background-jobs
by Alex Kumar 2 tabs
ruby
class NotifyFollowersJob
  include Sidekiq::Job

  sidekiq_options queue: :notifications, retry: 5

  def perform(post_id, actor_id)

Safer Background Job Arguments (Serialize IDs only)

rails reliability sidekiq
by codesnips 3 tabs
go
package mail

import (
  "context"
  "bytes"
  "encoding/json"

Email delivery via HTTP provider with context, timeout, and idempotency

go email background-jobs
by Leah Thompson 1 tab
sql
-- Product.active.touch_all(:cache_synced_at) for catalog 42
UPDATE "products"
SET "updated_at" = '2024-05-01 12:00:00.123456',
    "cache_synced_at" = '2024-05-01 12:00:00.123456'
WHERE "products"."catalog_id" = 42
  AND "products"."status" = 'active';

Use `touch_all` for Efficient “Bump Updated At”

rails activerecord performance
by codesnips 4 tabs
ruby
class Document < ApplicationRecord
  belongs_to :account

  validates :source_url, presence: true

  before_save :normalize_checksum

Prevent Long Transactions with after_save_commit for Heavy Work

rails activerecord background-jobs
by codesnips 3 tabs
ruby
class Order < ApplicationRecord
  belongs_to :customer

  scope :for_export, -> {
    select(:id, :reference, :total_cents, :currency, :created_at, :customer_id)
      .where.not(exported_at: nil)

Avoid Memory Blowups: find_each + select Columns

rails activerecord performance
by codesnips 3 tabs
typescript
import { Queue } from "bullmq";
import IORedis from "ioredis";

export const connection = new IORedis(process.env.REDIS_URL ?? "redis://localhost:6379", {
  maxRetriesPerRequest: null,
});

BullMQ worker with retries + dead-letter

node redis background-jobs
by codesnips 3 tabs
ruby
class Document < ApplicationRecord
  belongs_to :account

  enum status: { pending: 0, processing: 1, ready: 2, failed: 3 }

  after_create_commit :broadcast_badge

Broadcast a status badge update on background processing

rails hotwire turbo
by codesnips 4 tabs
ruby
class Post < ApplicationRecord
  has_many :comments, dependent: :destroy

  # comments_count is maintained by counter_cache on Comment#belongs_to

  scope :stale_comment_counts, lambda {

Counter Cache Repair Job (Consistency Tooling)

rails activerecord counter-cache
by codesnips 3 tabs
php
<?php

namespace App\Http\Controllers;

use App\Jobs\ProcessWebhook;
use App\Support\WebhookSignature;

Debounce Duplicate Webhooks in Laravel by Dispatching a Delayed Queued Job

laravel webhooks queues
by codesnips 3 tabs
php
<?php

namespace App\Event;

use Symfony\Contracts\EventDispatcher\Event;

Symfony: Send a Welcome Email Asynchronously with Messenger and an Event Subscriber

symfony messenger async
by codesnips 4 tabs