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
#generation, #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, stale
Methods included from Logging
log, #log
Constructor Details
#initialize(source, destination, encryption: nil, process: nil, **opts) ⇒ Task
Returns a new instance of Task.
783
784
785
786
787
788
789
|
# File 'lib/bitferry.rb', line 783
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.
768
769
770
|
# File 'lib/bitferry.rb', line 768
def destination
@destination
end
|
#encryption ⇒ Object
Returns the value of attribute encryption.
771
772
773
|
# File 'lib/bitferry.rb', line 771
def encryption
@encryption
end
|
#source ⇒ Object
Returns the value of attribute source.
768
769
770
|
# File 'lib/bitferry.rb', line 768
def source
@source
end
|
#token ⇒ Object
Returns the value of attribute token.
774
775
776
|
# File 'lib/bitferry.rb', line 774
def token
@token
end
|
Instance Method Details
#common_options ⇒ Object
822
823
824
825
826
827
828
829
830
831
832
833
|
# File 'lib/bitferry.rb', line 822
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
792
793
794
795
|
# File 'lib/bitferry.rb', line 792
def create(*args, process: nil, **opts)
super(*args, process: process, **opts)
encryption.configure(self) unless encryption.nil?
end
|
#execute(*args) ⇒ Object
843
844
845
846
847
848
849
850
851
|
# File 'lib/bitferry.rb', line 843
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 "rclone exit code #{status.exitstatus}" unless status.success?
status.success?
end
|
#externalize ⇒ Object
861
862
863
864
865
866
867
868
|
# File 'lib/bitferry.rb', line 861
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
|
819
|
# File 'lib/bitferry.rb', line 819
def format = nil
|
#intact? ⇒ Boolean
807
|
# File 'lib/bitferry.rb', line 807
def intact? = live? && source.intact? && destination.intact?
|
#process ⇒ Object
854
855
856
857
858
|
# File 'lib/bitferry.rb', line 854
def process
log.info("processing task #{tag}")
encryption.process(self) unless encryption.nil?
execute(*process_arguments)
end
|
#process_arguments ⇒ Object
836
837
838
839
840
|
# File 'lib/bitferry.rb', line 836
def process_arguments
['--filter', "- #{Volume::STORAGE}", '--filter', "- #{Volume::STORAGE_}"] + common_options + process_options + (
encryption.nil? ? [source.root.to_s, destination.root.to_s] : encryption.arguments(self)
)
end
|
#refers?(volume) ⇒ Boolean
810
|
# File 'lib/bitferry.rb', line 810
def refers?(volume) = source.refers?(volume) || destination.refers?(volume)
|
#restore(hash) ⇒ Object
871
872
873
874
875
876
877
878
879
880
881
|
# File 'lib/bitferry.rb', line 871
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
804
|
# File 'lib/bitferry.rb', line 804
def show_direction = '-->'
|
#show_operation ⇒ Object
801
|
# File 'lib/bitferry.rb', line 801
def show_operation = encryption.nil? ? '' : encryption.show_operation
|
#show_status ⇒ Object
798
|
# File 'lib/bitferry.rb', line 798
def show_status = "#{show_operation} #{source.show_status} #{show_direction} #{destination.show_status}"
|
#touch ⇒ Object
813
814
815
816
|
# File 'lib/bitferry.rb', line 813
def touch
@generation = [source.generation, destination.generation].max + 1
super
end
|