Class: Syncthing::Helper::CLI::UpdaterCommand

Inherits:
AbstractCommand
  • Object
show all
Defined in:
lib/syncthing/helper/cli/updater_command.rb

Instance Method Summary collapse

Methods included from InstanceMethods

#col, #delete_record, #query, #tabled_stdout, #trigger_updates

Instance Method Details

#api_keyObject



35
36
37
# File 'lib/syncthing/helper/cli/updater_command.rb', line 35

def api_key
  syncthing_api_key || Syncthing::Helper::API.api_key_from_xml(xml_config)
end

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/syncthing/helper/cli/updater_command.rb', line 8

def execute
  super
  config_obj = API::Config.new
  config_obj.connect(syncthing_uri: syncthing_uri,
                     syncthing_api_key: api_key)

  %w(devices folders).each do |col_name|
    klass = ('Syncthing::Helper::API::' + col_name.capitalize + 'Updater').constantize
    instance_variable_set ('@' + col_name).to_sym, klass.new(config_obj: config_obj, col: col_name)
  end

  %w(term int quit).map(&:upcase).each do |sig|
    Signal.trap(sig) do
      Thread.new {shutdown}
      exit
    end
  end

  loop { sleep 60 }
end

#shutdownObject



29
30
31
32
33
# File 'lib/syncthing/helper/cli/updater_command.rb', line 29

def shutdown
  @devices.listener.stop
  @folders.listener.stop
  sleep 5
end