Skip to content

Instantly share code, notes, and snippets.

@zerebral
Last active December 21, 2017 08:02
Show Gist options
  • Save zerebral/3c50dedb679dd555ea683a999088f019 to your computer and use it in GitHub Desktop.
Save zerebral/3c50dedb679dd555ea683a999088f019 to your computer and use it in GitHub Desktop.
Watch a directory for new files and move those to Gcloud
require "ap"
path = ARGV[0]
bucket = ARGV[1]
while true do
files = Dir.glob("#{path}/*.jsar").select{|f| (Time.now - File.mtime(f)) > 60}
puts "-- Files to move - #{files.size}"
files.each{|file|
puts "-- -- Moving #{file}"
`gsutil -m mv #{file} #{bucket}`
}
sleep 5
end
@zerebral
Copy link
Author

Better version to parallely upload multiple files - 10 by default (-m option)

require "ap"
path = ARGV[0]
bucket = ARGV[1]

mkdir #{path}/inprogress
while true do
files = Dir.glob("#{path}/*.jsar").select{|f| (Time.now - File.mtime(f)) > 60}

puts "-- Files to move - #{files.size}"
puts "-- -- Moving #{files.take(10)}"
files.take(10).each{|f| mv #{f} #{path}/inprogress/}
gsutil -m mv #{path}/inprogress #{bucket}
sleep 3 if files.size < 10
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment