Created
April 12, 2025 09:55
-
-
Save pmatsinopoulos/0eafae7b6c6eefbbbc48235002fdf81e to your computer and use it in GitHub Desktop.
Using #increment!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculateUserBalanceJob < ApplicationJob | |
queue_as :default | |
def perform(user_id) | |
user = User.find(user_id) | |
puts "#{Thread.current.object_id} -> Calculating balance for user: #{user.email}" | |
user_balance = user.user_balance | |
# Simulate a long-running calculation | |
sleep rand(5..10) | |
user_balance.increment!(:balance, 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment