Class: Bitferry::Rclone::Task
- Inherits:
-
Task
- Object
- Task
- Bitferry::Rclone::Task
show all
- Defined in:
- lib/bitferry.rb
Constant Summary
collapse
- PROCESS =
{
default: ['--metadata']
}
Constants inherited
from Task
Task::ROUTE
Instance Attribute Summary collapse
Attributes inherited from Task
#exclude, #generation, #include, #modified, #tag
Instance Method Summary
collapse
Methods inherited from Task
[], #commit, #delete, delete, intact, live, #live?, lookup, match, new, #process_options, register, registered, reset, restore, #restore_endpoint, #show_filters, stale
Methods included from Logging
log, #log, log=
Constructor Details
#initialize(source, destination, encryption: nil, process: nil, **opts) ⇒ Task
Returns a new instance of Task.
842
843
844
845
846
847
848
|
# File 'lib/bitferry.rb', line 842
def initialize(source, destination, encryption: nil, process: nil, **opts)
super(**opts)
@process_options = Bitferry.optional(process, PROCESS)
@source = source.is_a?(Endpoint) ? source : Bitferry.endpoint(source)
@destination = destination.is_a?(Endpoint) ? destination : Bitferry.endpoint(destination)
@encryption = encryption
end
|
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
827
828
829
|
# File 'lib/bitferry.rb', line 827
def destination
@destination
end
|
#encryption ⇒ Object
Returns the value of attribute encryption.
830
831
832
|
# File 'lib/bitferry.rb', line 830
def encryption
@encryption
end
|
#source ⇒ Object
Returns the value of attribute source.
827
828
829
|
# File 'lib/bitferry.rb', line 827
def source
@source
end
|
#token ⇒ Object
Returns the value of attribute token.
833
834
835
|
# File 'lib/bitferry.rb', line 833
def token
@token
end
|
Instance Method Details
#common_options ⇒ Object
881
882
883
884
885
886
887
888
889
890
891
892
|
# File 'lib/bitferry.rb', line 881
def common_options
[
'--config', Bitferry.windows? ? 'NUL' : '/dev/null',
case Bitferry.verbosity
when :verbose then '--verbose'
when :quiet then '--quiet'
else nil
end,
Bitferry.verbosity == :verbose ? '--progress' : nil,
Bitferry.simulate? ? '--dry-run' : nil,
].compact
end
|
#create(*args, process: nil, **opts) ⇒ Object
851
852
853
854
|
# File 'lib/bitferry.rb', line 851
def create(*args, process: nil, **opts)
super(*args, process: process, **opts)
encryption.configure(self) unless encryption.nil?
end
|
#exclude_filters ⇒ Object
898
|
# File 'lib/bitferry.rb', line 898
def exclude_filters = ([Volume::STORAGE, Volume::STORAGE_] + exclude).collect { |x| ['--filter', "- #{x}"]}.flatten
|
#execute(*args) ⇒ Object
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
|
# File 'lib/bitferry.rb', line 908
def execute(*args)
cmd = [Rclone.executable] + args
cms = cmd.collect(&:shellescape).join(' ')
$stdout.puts cms if Bitferry.verbosity == :verbose
log.info(cms)
if Bitferry.ui == :gui
t = nil
Open3.popen2e(*cmd) do |i, oe, thr|
while x = oe.gets; $stdout.puts(x) end
t = thr
end
status = t.value
else
status = Open3.pipeline(cmd).first
end
raise RuntimeError, "rclone exit code #{status.exitstatus}" unless status.success?
status.success?
end
|
#externalize ⇒ Object
935
936
937
938
939
940
941
942
|
# File 'lib/bitferry.rb', line 935
def externalize
super.merge(
source: source.externalize,
destination: destination.externalize,
encryption: encryption.nil? ? nil : encryption.externalize,
rclone: process_options.empty? ? nil : process_options
).compact
end
|
878
|
# File 'lib/bitferry.rb', line 878
def format = nil
|
#include_filters ⇒ Object
895
|
# File 'lib/bitferry.rb', line 895
def include_filters = include.collect { |x| ['--filter', "+ #{x}"]}.flatten
|
#intact? ⇒ Boolean
866
|
# File 'lib/bitferry.rb', line 866
def intact? = live? && source.intact? && destination.intact?
|
#process ⇒ Object
928
929
930
931
932
|
# File 'lib/bitferry.rb', line 928
def process
log.info("processing task #{tag}")
encryption.process(self) unless encryption.nil?
execute(*process_arguments)
end
|
#process_arguments ⇒ Object
901
902
903
904
905
|
# File 'lib/bitferry.rb', line 901
def process_arguments
include_filters + exclude_filters + common_options + process_options + (
encryption.nil? ? [source.root.to_s, destination.root.to_s] : encryption.arguments(self)
)
end
|
#refers?(volume) ⇒ Boolean
869
|
# File 'lib/bitferry.rb', line 869
def refers?(volume) = source.refers?(volume) || destination.refers?(volume)
|
#restore(hash) ⇒ Object
945
946
947
948
949
950
951
952
953
954
955
|
# File 'lib/bitferry.rb', line 945
def restore(hash)
initialize(
restore_endpoint(hash.fetch(:source)),
restore_endpoint(hash.fetch(:destination)),
tag: hash.fetch(:task),
modified: hash.fetch(:modified, DateTime.now),
process: hash[:rclone],
encryption: hash[:encryption].nil? ? nil : Rclone::Encryption.restore(hash[:encryption])
)
super(hash)
end
|
#show_direction ⇒ Object
863
|
# File 'lib/bitferry.rb', line 863
def show_direction = '-->'
|
#show_operation ⇒ Object
860
|
# File 'lib/bitferry.rb', line 860
def show_operation = encryption.nil? ? '' : encryption.show_operation
|
#show_status ⇒ Object
857
|
# File 'lib/bitferry.rb', line 857
def show_status = "#{show_operation} #{source.show_status} #{show_direction} #{destination.show_status} #{show_filters}"
|
#touch ⇒ Object
872
873
874
875
|
# File 'lib/bitferry.rb', line 872
def touch
@generation = [source.generation, destination.generation].max + 1
super
end
|