Class: Panoramix::Plugin::S3
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Instance Method Summary collapse
-
#clean ⇒ Object
Action clean fot this task.
-
#created? ⇒ Boolean
Has this instance already been created.
-
#initialize(dst, src, flags) ⇒ S3
constructor
A new instance of S3.
-
#needed?(timestamps) ⇒ Boolean
When this instance needs to be executed.
-
#run_default ⇒ Object
Default action for this task.
-
#timestamp ⇒ Object
Return current timestamp.
Methods inherited from Base
Constructor Details
#initialize(dst, src, flags) ⇒ S3
Returns a new instance of S3.
12 13 14 15 16 |
# File 'lib/panoramix/plugin/s3.rb', line 12 def initialize(dst, src, flags) @dst = dst @src = src @flags = flags end |
Instance Attribute Details
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
8 9 10 |
# File 'lib/panoramix/plugin/s3.rb', line 8 def dst @dst end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
10 11 12 |
# File 'lib/panoramix/plugin/s3.rb', line 10 def flags @flags end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
9 10 11 |
# File 'lib/panoramix/plugin/s3.rb', line 9 def src @src end |
Instance Method Details
#clean ⇒ Object
Action clean fot this task
42 43 44 |
# File 'lib/panoramix/plugin/s3.rb', line 42 def clean shell "rm -f #{@dst}" end |
#created? ⇒ Boolean
Has this instance already been created
37 38 39 |
# File 'lib/panoramix/plugin/s3.rb', line 37 def created? File.exists?(@dst) end |
#needed?(timestamps) ⇒ Boolean
When this instance needs to be executed
30 31 32 33 34 |
# File 'lib/panoramix/plugin/s3.rb', line 30 def needed? return true if !created? remote_size = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $3}'", true)[:out] File.mtime(@dst) < || File.size(@dst) != remote_size.to_i end |
#run_default ⇒ Object
Default action for this task
47 48 49 |
# File 'lib/panoramix/plugin/s3.rb', line 47 def run_default shell "aws s3 cp #{@flags} #{@src} #{@dst}" end |
#timestamp ⇒ Object
Return current timestamp
19 20 21 22 23 24 25 26 27 |
# File 'lib/panoramix/plugin/s3.rb', line 19 def 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 |