background-jobs

ruby
class CommentsChannel < ApplicationCable::Channel
  def subscribed
    post = find_post
    if post
      stream_for post
    else

Broadcasting New Comments to Subscribers over an ActionCable Channel

rails actioncable websockets
by codesnips 4 tabs
java
@Component
public class SalesRollupScheduler {

    private static final Logger log = LoggerFactory.getLogger(SalesRollupScheduler.class);
    private static final int ROLLUP_WINDOW_DAYS = 3;

Roll Up Daily Sales Totals With a Scheduled Spring Batch Upsert via JdbcTemplate

spring-boot jdbctemplate postgres
by codesnips 3 tabs
ruby
class CreateStripeEvents < ActiveRecord::Migration[7.1]
  def change
    create_table :stripe_events do |t|
      t.string :stripe_event_id, null: false
      t.string :event_type, null: false
      t.string :status, null: false, default: "received"

Idempotent Stripe Webhook Processing in Rails with a Durable Event Log

rails stripe webhooks
by codesnips 4 tabs
ruby
require "sidekiq/api"

class QueueDepthGuard
  class QueueSaturated < StandardError
    attr_reader :queue, :depth

Background Job Backpressure with Queue Depth Guard

rails reliability sidekiq
by codesnips 3 tabs
ruby
module StatementTimeout
  extend ActiveSupport::Concern

  class TimeoutExceeded < StandardError; end

  def with_statement_timeout(milliseconds)

Guard Against Slow Queries with statement_timeout

rails postgres performance
by codesnips 3 tabs
ruby
class RegistrationsController < ApplicationController
  def new
    @user = User.new
  end

  def create

Send a Welcome Email After Signup Using a Sidekiq Background Job in Rails

ruby rails sidekiq
by codesnips 4 tabs
go
package jobs

import (
  "context"
  "math/rand"
  "time"

Robfig cron jobs with context cancellation and jitter

go cron background-jobs
by Leah Thompson 1 tab
ruby
class Import < ApplicationRecord
  include ActionView::RecordIdentifier

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

  has_one_attached :file

Broadcast job progress updates to a Turbo Frame

rails hotwire turbo-streams
by codesnips 4 tabs
typescript
import { Queue } from "bullmq";
import { createHash } from "crypto";

export const connection = { host: "127.0.0.1", port: 6379 };

export interface ChargePayload {

BullMQ job idempotency via dedupe id

node redis background-jobs
by codesnips 3 tabs
ruby
class UserNotificationJob < ApplicationJob
  queue_as :default

  # Retry up to 5 times with exponential backoff
  retry_on StandardError, wait: :exponentially_longer, attempts: 5

Background jobs with Sidekiq and ActiveJob

ruby rails sidekiq
by Sarah Mitchell 3 tabs
ruby
class AddSoftDeleteToDocuments < ActiveRecord::Migration[7.0]
  disable_ddl_transaction!

  def change
    add_column :documents, :marked_for_deletion_at, :datetime, null: true

Safer Time-Based Deletes with “mark then sweep”

rails reliability activerecord
by codesnips 4 tabs
typescript
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bull';
import { ScheduleModule } from '@nestjs/schedule';
import { DigestProducer } from './digest.producer';
import { DigestProcessor } from './digest.processor';

Scheduling and Processing Email Digests with a Bull Queue in NestJS

nestjs bull redis
by codesnips 3 tabs