Class: Bitferry::Rclone::Task

Inherits:
Task
  • Object
show all
Defined in:
lib/bitferry.rb

Direct Known Subclasses

Copy, Equalize, Synchronize, Update

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.



786
787
788
789
790
791
792
# File 'lib/bitferry.rb', line 786

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

#destinationObject (readonly)

Returns the value of attribute destination.



771
772
773
# File 'lib/bitferry.rb', line 771

def destination
  @destination
end

#encryptionObject (readonly)

Returns the value of attribute encryption.



774
775
776
# File 'lib/bitferry.rb', line 774

def encryption
  @encryption
end

#sourceObject (readonly)

Returns the value of attribute source.



771
772
773
# File 'lib/bitferry.rb', line 771

def source
  @source
end

#tokenObject (readonly)

Returns the value of attribute token.



777
778
779
# File 'lib/bitferry.rb', line 777

def token
  @token
end

Instance Method Details

#common_optionsObject



825
826
827
828
829
830
831
832
833
834
835
836
# File 'lib/bitferry.rb', line 825

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



795
796
797
798
# File 'lib/bitferry.rb', line 795

def create(*args, process: nil, **opts)
  super(*args, process: process, **opts)
  encryption.configure(self) unless encryption.nil?
end

#execute(*args) ⇒ Object



846
847
848
849
850
851
852
853
854
# File 'lib/bitferry.rb', line 846

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

#externalizeObject



864
865
866
867
868
869
870
871
# File 'lib/bitferry.rb', line 864

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

#formatObject



822
# File 'lib/bitferry.rb', line 822

def format = nil

#intact?Boolean

Returns:

  • (Boolean)


810
# File 'lib/bitferry.rb', line 810

def intact? = live? && source.intact? && destination.intact?

#processObject



857
858
859
860
861
# File 'lib/bitferry.rb', line 857

def process
  log.info("processing task #{tag}")
  encryption.process(self) unless encryption.nil?
  execute(*process_arguments)
end

#process_argumentsObject



839
840
841
842
843
# File 'lib/bitferry.rb', line 839

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

Returns:

  • (Boolean)


813
# File 'lib/bitferry.rb', line 813

def refers?(volume) = source.refers?(volume) || destination.refers?(volume)

#restore(hash) ⇒ Object



874
875
876
877
878
879
880
881
882
883
884
# File 'lib/bitferry.rb', line 874

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_directionObject



807
# File 'lib/bitferry.rb', line 807

def show_direction = '-->'

#show_operationObject



804
# File 'lib/bitferry.rb', line 804

def show_operation = encryption.nil? ? '' : encryption.show_operation

#show_statusObject



801
# File 'lib/bitferry.rb', line 801

def show_status = "#{show_operation} #{source.show_status} #{show_direction} #{destination.show_status}"

#touchObject



816
817
818
819
# File 'lib/bitferry.rb', line 816

def touch
  @generation = [source.generation, destination.generation].max + 1
  super
end