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
Constructor Details
#initialize(source, destination, encryption: nil, process: nil, **opts) ⇒ Task
Returns a new instance of Task.
818
819
820
821
822
823
824
|
# File 'lib/bitferry.rb', line 818
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.
803
804
805
|
# File 'lib/bitferry.rb', line 803
def destination
@destination
end
|
#encryption ⇒ Object
Returns the value of attribute encryption.
806
807
808
|
# File 'lib/bitferry.rb', line 806
def encryption
@encryption
end
|
#source ⇒ Object
Returns the value of attribute source.
803
804
805
|
# File 'lib/bitferry.rb', line 803
def source
@source
end
|
#token ⇒ Object
Returns the value of attribute token.
809
810
811
|
# File 'lib/bitferry.rb', line 809
def token
@token
end
|
Instance Method Details
#common_options ⇒ Object
857
858
859
860
861
862
863
864
865
866
867
868
|
# File 'lib/bitferry.rb', line 857
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
827
828
829
830
|
# File 'lib/bitferry.rb', line 827
def create(*args, process: nil, **opts)
super(*args, process: process, **opts)
encryption.configure(self) unless encryption.nil?
end
|
#exclude_filters ⇒ Object
874
|
# File 'lib/bitferry.rb', line 874
def exclude_filters = ([Volume::STORAGE, Volume::STORAGE_] + exclude).collect { |x| ['--filter', "- #{x}"]}.flatten
|
#execute(*args) ⇒ Object
884
885
886
887
888
889
890
891
892
|
# File 'lib/bitferry.rb', line 884
def execute(*args)
cmd = [Rclone.executable] + args
cms = cmd.collect(&:shellescape).join(' ')
puts cms if Bitferry.verbosity == :verbose
log.info(cms)
status = Open3.pipeline(cmd).first
raise RuntimeError, "rclone exit code #{status.exitstatus}" unless status.success?
status.success?
end
|
#externalize ⇒ Object
902
903
904
905
906
907
908
909
|
# File 'lib/bitferry.rb', line 902
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
|
854
|
# File 'lib/bitferry.rb', line 854
def format = nil
|
#include_filters ⇒ Object
871
|
# File 'lib/bitferry.rb', line 871
def include_filters = include.collect { |x| ['--filter', "+ #{x}"]}.flatten
|
#intact? ⇒ Boolean
842
|
# File 'lib/bitferry.rb', line 842
def intact? = live? && source.intact? && destination.intact?
|
#process ⇒ Object
895
896
897
898
899
|
# File 'lib/bitferry.rb', line 895
def process
log.info("processing task #{tag}")
encryption.process(self) unless encryption.nil?
execute(*process_arguments)
end
|
#process_arguments ⇒ Object
877
878
879
880
881
|
# File 'lib/bitferry.rb', line 877
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
845
|
# File 'lib/bitferry.rb', line 845
def refers?(volume) = source.refers?(volume) || destination.refers?(volume)
|
#restore(hash) ⇒ Object
912
913
914
915
916
917
918
919
920
921
922
|
# File 'lib/bitferry.rb', line 912
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
839
|
# File 'lib/bitferry.rb', line 839
def show_direction = '-->'
|
#show_operation ⇒ Object
836
|
# File 'lib/bitferry.rb', line 836
def show_operation = encryption.nil? ? '' : encryption.show_operation
|
#show_status ⇒ Object
833
|
# File 'lib/bitferry.rb', line 833
def show_status = "#{show_operation} #{source.show_status} #{show_direction} #{destination.show_status} #{show_filters}"
|
#touch ⇒ Object
848
849
850
851
|
# File 'lib/bitferry.rb', line 848
def touch
@generation = [source.generation, destination.generation].max + 1
super
end
|