class Panoramix::Plugin::S3

Attributes

dst[R]
flags[R]
src[R]

Public Class Methods

new(dst, src, flags) click to toggle source
# File lib/panoramix/plugin/s3.rb, line 12
def initialize(dst, src, flags)
        @dst = dst
        @src = src
        @flags = flags
end

Public Instance Methods

clean() click to toggle source

Action clean fot this task

# File lib/panoramix/plugin/s3.rb, line 42
def clean
        shell "rm -f #{@dst}"
end
created?() click to toggle source

Has this instance already been created

# File lib/panoramix/plugin/s3.rb, line 37
def created?
        File.exists?(@dst)
end
needed?(timestamps) click to toggle source

When this instance needs to be executed

# File lib/panoramix/plugin/s3.rb, line 30
def needed? timestamps
        return true if !created?
        remote_size = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $3}'", true)[:out]
        File.mtime(@dst) < timestamp || File.size(@dst) != remote_size.to_i
end
run_default() click to toggle source

Default action for this task

# File lib/panoramix/plugin/s3.rb, line 47
def run_default
        shell "aws s3 cp #{@flags} #{@src} #{@dst}"
end
timestamp() click to toggle source

Return current timestamp

# File lib/panoramix/plugin/s3.rb, line 19
def timestamp
        return Time.at 0 unless created?
        remote_time = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $1, $2}'", true)[:out]
        while remote_time == " \n"
                sleep 1
                remote_time = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $1, $2}'", true)[:out]
        end
  remote_time = Time.parse(remote_time)
end