简体   繁体   中英

How to make external API calls with Rake for long running task

I have a Rails 4 application with my model User and in another Rails 4 application I have a similar model, but not the same. I want to 'connect' the users from app1 to app2 by a token. In short, I don't want my users from app1 to signup in app2, they must have a easy way to access app2.

I must save one token1 in my user from app1 by making a POST request in my app2 that will create the user and will return token1 to be saved on the user from app1. The token will be used not only for authentication. Oauth is not an option.

So I have around a thousand users in app1 and I need to automate this process.

My idea was to make a rake that will do the POST request for every user and in response would set the token1.

My doubts:

  • is that a good approach ?
  • is rake appropriate ?
  • if so, which lib/gem would be best to achieve the POST request?
  • how do I make this happen safely/correct ? transactions ?
  • how do I guarantee that all the users got the token1 setted ?
  • how do I make this without bombarding my app2 with several requests at once ? should happen in a nice pace
  • how do I deal with a bad request ? It should only set the token1 if the request was successful and returned the token

Consider setting your own oauth server . Using oauth, user can automatically authenticate on both sites.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM