Falcon::RailsGuidesJob Processing

Job Processing

This guide explains how to implement background job processing with Falcon and Rails using the async-job gem.

What is Async::Job?

Async::Job is a framework for creating background jobs that run asynchronously without blocking web requests. It integrates seamlessly with Rails' ActiveJob, allowing you to offload long-running tasks to background workers. The Rails integration uses a specific gem to provide this functionality, called async-job-adapter-active_job.

When to use async jobs:

When NOT to use async jobs:

Basic Implementation

Server-Side: Job Class

Create a job class that inherits from ApplicationJob:

class MyJob < ApplicationJob
	# Specify the queue adapter per-job rather than globally:
	# queue_adapter :async_job
	
	queue_as "default"
	
	def perform
		# ... work ...
	end
end

Key Points:

Configuration

Configure async-job queues in config/initializers/async_job.rb:

require 'async/job'
require 'async/job/processor/aggregate'
require 'async/job/processor/redis'
require 'async/job/processor/inline'

Rails.application.configure do
	config.async_job.define_queue "default" do
		# Double-buffers incoming jobs to avoid submission latency:
		enqueue Async::Job::Processor::Aggregate
		dequeue Async::Job::Processor::Redis
	end
	
	config.async_job.define_queue "local" do
		dequeue Async::Job::Processor::Inline
	end
end

Key Points:

Configure the default adapter in config/application.rb:

# ... in the application configuration:
config.active_job.queue_adapter = :async_job

Key Points: