Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

force token refresh to avoid race condition

  • Loading branch information...
commit b96b810260c1bbdc5643eca399baf8503d3408ac 1 parent 105de9d
@igrigorik authored
Showing with 19 additions and 1 deletion.
  1. +2 −0  bigquery/.gitignore
  2. +17 −1 bigquery/sync.rb
View
2  bigquery/.gitignore
@@ -0,0 +1,2 @@
+*.token
+tools
View
18 bigquery/sync.rb
@@ -1,7 +1,10 @@
require 'optparse'
require 'time'
+require 'json'
-options = {verbose: false, sync: true}
+ARGV << '--help' if ARGV.empty?
+
+options = {verbose: false, sync: true, token: '.bigquery.v2.token'}
OptionParser.new do |opts|
opts.banner = "Usage: sync.rb [options]"
@@ -13,6 +16,10 @@
options[:sync] = v
end
+ opts.on("-t", "--token FILE", "token filename") do |v|
+ options[:token] = v
+ end
+
opts.on("-v", "--verbose", "verbose log") do |v|
options[:verbose] = v
end
@@ -24,9 +31,18 @@
r = system("ruby transform.rb -i #{options[:file]} -o /tmp/bq.csv #{'-v' if options[:verbose]}")
exit(1) if !r
+# expire current oauth token
+j = JSON.parse(IO.read(options[:token]))
+j['access_token'] = 'expired'
+
+# force refresh of the current token
+File.open(options[:token], 'w') {|f| f.write JSON.generate(j)}
+system("/usr/local/bin/bq --credential_file /home/archiver/githubarchive/bigquery/.bigquery.v2.token ls")
+
# upload the data to BigQuery
system("/usr/local/bin/bq #{'--nosync' if !options[:sync]} " +
"#{'--apilog true' if options[:verbose]} " +
+ "--credential_file /home/archiver/githubarchive/bigquery/.bigquery.v2.token " +
"load github.events /tmp/bq.csv.gz")
File.unlink("/tmp/bq.csv.gz")
Please sign in to comment.
Something went wrong with that request. Please try again.