Class: Panoramix::Plugin::S3

Inherits:
Base
  • Object
show all
Defined in:
lib/panoramix/plugin/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#shell

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

#dstObject (readonly)

Returns the value of attribute dst.



8
9
10
# File 'lib/panoramix/plugin/s3.rb', line 8

def dst
  @dst
end

#flagsObject (readonly)

Returns the value of attribute flags.



10
11
12
# File 'lib/panoramix/plugin/s3.rb', line 10

def flags
  @flags
end

#srcObject (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

#cleanObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


30
31
32
33
34
# 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_defaultObject

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

#timestampObject

Return current timestamp



19
20
21
22
23
24
25
26
27
# 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