background-jobs

php
<?php

namespace App\Providers;

use App\Events\OrderPlaced;
use App\Listeners\DecrementInventory;

Fan Out an Order Placed Domain Event to Multiple Queued Laravel Listeners

laravel events queues
by codesnips 4 tabs
python
import uuid
from django.db import models
from django.utils import timezone


class OutboxManager(models.Manager):

Transactional Outbox with Timer-Based Flushing and Exponential Backoff in Django

django outbox postgres
by codesnips 3 tabs
ruby
module Notifications
  class RecipientSerializer < ActiveJob::Serializers::ObjectSerializer
    def serialize?(argument)
      argument.is_a?(Notifications::Recipient)
    end

Enqueuing Notification Batches with a Custom Active Job Argument Serializer for Value Objects

rails active-job serialization
by codesnips 4 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Batching Laravel Queue Jobs to Roll Up Daily Order Totals With a Completion Callback

laravel queues background-jobs
by codesnips 3 tabs
java
@Configuration
@EnableScheduling
@EnableConfigurationProperties(CleanupProperties.class)
public class SchedulingConfig {

    @Bean(destroyMethod = "shutdown")

Recurring Cleanup Job with Spring @Scheduled and a Shutdown-Aware Executor

spring spring-boot scheduling
by codesnips 3 tabs
ruby
class Cart < ApplicationRecord
  has_many :cart_items, dependent: :destroy

  EXPIRY_WINDOW = 2.hours

  scope :active, -> { where(state: :active) }

Expire Stale Shopping Carts With a Rails Scope and a Recurring Reaper Job

rails activerecord background-jobs
by codesnips 3 tabs
ruby
class Order < ApplicationRecord
  include TransactionalEnqueue

  belongs_to :customer
  has_many :line_items, dependent: :destroy

Transaction-Safe After-Commit Hook (Avoid Ghost Jobs)

rails activerecord background-jobs
by codesnips 4 tabs
php
<?php

namespace App\Http\Controllers;

use App\Jobs\ImportProductChunk;
use Illuminate\Http\Request;

Chunked CSV Product Import with Laravel Queued Jobs and LazyCollection

laravel queue background-jobs
by codesnips 3 tabs
php
<?php

namespace App\Http\Controllers;

use App\Jobs\ImportProductChunk;
use App\Models\Import;

Chunked CSV Product Import With Laravel Batched Queue Jobs

laravel queue csv
by codesnips 3 tabs
ruby
module DomainEvents
  class Registry
    def initialize
      @subscribers = Hash.new { |h, k| h[k] = [] }
    end

Avoid Callback Chains: Use Domain Events (In-App)

rails architecture domain-events
by codesnips 4 tabs
ruby
class DownloadsController < ApplicationController
  before_action :authenticate_user!

  def show
    report = current_account.reports.find(params[:report_id])
    authorize! :download, report

Signed, Expiring S3 Download URLs for Active Storage Attachments in Rails

rails active-storage s3
by codesnips 4 tabs
go
package scheduler

import (
	"context"
	"log"
	"sync"

Graceful Cron-Style Scheduler in Go With Ticker and Context Cancellation

scheduler ticker context
by codesnips 3 tabs