Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmatsinopoulos/4b42cba1efbbbf7e3b9b57471396cbbf to your computer and use it in GitHub Desktop.
Save pmatsinopoulos/4b42cba1efbbbf7e3b9b57471396cbbf to your computer and use it in GitHub Desktop.
Update balance to a random value
class CalculateUserBalanceJob < ApplicationJob
queue_as :default
def perform(user_id)
user = User.find(user_id)
puts "Calculating balance for user: #{user.email}"
user_balance = user.user_balance
sleep rand(5..10)
new_balance = rand(5..50)
user_balance.update!(balance: new_balance, job_id: provider_job_id)
JobLog.create!(job_id: provider_job_id, balance: new_balance)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment