Skip to content

Instantly share code, notes, and snippets.

@tansengming
Created February 21, 2017 16:18
Show Gist options
  • Save tansengming/edf4e1dbce5acd5b159f91a42f77b4d2 to your computer and use it in GitHub Desktop.
Save tansengming/edf4e1dbce5acd5b159f91a42f77b4d2 to your computer and use it in GitHub Desktop.
commnunity.users.each do |recipient|
sms_credits = community.sms_credits
if sms_credits > 0
# this chucks the job into a queue and returns immediately!
SmsSenderJob.perform_later recipient, 'Everything is fine.'
# take off a credit
community.sms_credits = sms_credits - 1
community.save
end
end
class SmsSenderJob < ApplicationJob
def perform(recipient, message)
send_sms(recipient, message)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment