Last active
          December 21, 2017 08:02 
        
      - 
      
- 
        Save zerebral/3c50dedb679dd555ea683a999088f019 to your computer and use it in GitHub Desktop. 
    Watch a directory for new files and move those to Gcloud
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Better version to parallely upload multiple files - 10 by default (-m option)
require "ap"
path = ARGV[0]
bucket = ARGV[1]
mkdir #{path}/inprogresswhile 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