Menu

ActiveJob Too? Sure, Let's Explain Jobs, Queues, and Adapters with a Restaurant Again
πŸ“°

ActiveJob Too? Sure, Let's Explain Jobs, Queues, and Adapters with a Restaurant Again

DEV Community: railsΒ·KaziuΒ·about 6 hours ago
#SfMEPVa8
#devtorails#devto#dev#order#board
Reading 0:00
15s threshold

Yeah, I know, I know. But let me compare it to a restaurant anyway.

The cast

First, a mapping table. I'll stick with this analogy for the whole post.

Rails term In restaurant terms

Web request An order from a customer who walked in

Controller Cashier

Job Order ticket

perform_later Pinning the order ticket to the board

Queue The board where order tickets are pinned

Worker Cook

Adapter The type of board

Why do things "later" at all?

Say we have a feature that sends a welcome email when a user signs up.

class UsersController < ApplicationController def create user = User . create! ( user_params ) WelcomeMailer . with ( user : user ) . welcome . deliver_now # ← you get stuck waiting a few seconds here render json : user end end

Enter fullscreen mode

Exit fullscreen mode

This is like the cashier taking an order, walking into the kitchen to cook it themselves, and not coming back to the register until it's done .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.