Skip to content

Instantly share code, notes, and snippets.

@andrius
Created April 16, 2013 20:55
Show Gist options
  • Save andrius/5399575 to your computer and use it in GitHub Desktop.
Save andrius/5399575 to your computer and use it in GitHub Desktop.
Any way to optimize? To ensure that its working on MySQL, SQLITE, Postgre SQL?
# Find next number to send call
def next_number
# first parse CDRs
Cdr.parse
# find number
sql_request = %{campaign_id = ? and
call_state = ? and
number_of_retries < ? and
(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(updated_at)) <= ?
}.gsub(/\s+/," ").chomp.strip
CampaignNumber.where(sql_request, self.id, "idle",
amount_of_max_attempts,
minimal_timeout_between_retrials
).order("number_of_retries, updated_at").first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment