Skip to content

Instantly share code, notes, and snippets.

@pmatsinopoulos
Created April 12, 2025 09:55
Show Gist options
  • Save pmatsinopoulos/0eafae7b6c6eefbbbc48235002fdf81e to your computer and use it in GitHub Desktop.
Save pmatsinopoulos/0eafae7b6c6eefbbbc48235002fdf81e to your computer and use it in GitHub Desktop.
Using #increment!
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