I would like to ask if there is any way how to update database from external source to my Rails DB constantly (every 1 hour)...
I was trying to do that but when i do that my DB is duplicated + added new files so is there any if
statement where can i just add new values?
- I'm pulling DB (JSON) from BitBucket(commits)
- Then i'm saving that into my Rails DB and returning in view.
- I tried for that use whenever gem.
bitbucket.rb
class Bitbucket < ActiveRecord::Base
def self.savedata
require 'bitbucket_rest_api'
bitbucket = BitBucket.new login:'...', password:'...'
repo = bitbucket.repos.commits.list '...', '...'
repo["values"].each do |r|
create(
name: r["author"]["user"]["display_name"],
message: r["message"],
date: r["date"]
)
end
end
end
I have to run first in Rails console Bitbucket.connection
then Bitbucket.savedata
to save into DB.
Thanks for any advice and help.
Aucun commentaire:
Enregistrer un commentaire