Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from crova/Controller
Created January 30, 2017 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radar/d9ad40ead59e1ec00b35fa3a36af77be to your computer and use it in GitHub Desktop.
Save radar/d9ad40ead59e1ec00b35fa3a36af77be to your computer and use it in GitHub Desktop.
How to run this task with delayed_job
# fetchs SIB Account information
def sib_account_fetch
sib = Mailin.new("API_URL","API_KEY")
acct = sib.get_account()
acct.dig('data')
credits = acct.dig('data', 0).to_h
SibAccount.find(1).update_attributes(credits)
details = acct.dig('data', 2).to_h
SibAccount.find(1).update_attributes(details).delay
redirect_to(:controller => 'monet', :action => 'refresh')
flash[:notice] = "Account Info updated successfully."
end
class CreditFetcher
def run
sib = Mailin.new("API_URL","API_KEY")
acct = sib.get_account()
acct.dig('data')
credits = acct.dig('data', 0).to_h
SibAccount.find(1).update_attributes(credits)
details = acct.dig('data', 2).to_h
SibAccount.find(1).update_attributes(details).delay
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment