Class: Restforce::DB::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/db/command.rb

Overview

Restforce::DB::Command represents the command line interface for our daemonized processing loop. It captures a set of options from the command line to configure the running worker thread for synchronizing data.

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Public: Initialize a new Restforce::DB::Command.

args - A set of command line arguments to pass to the OptionParser.



16
17
18
19
20
21
22
23
24
25
# File 'lib/restforce/db/command.rb', line 16

def initialize(args)
  @options = {
    pid_dir: Rails.root.join("tmp", "pids"),
    config:  Rails.root.join("config", "restforce-db.yml"),
    tracker: Rails.root.join("config", ".restforce"),
    logfile: Rails.root.join("log", "restforce-db.log"),
  }

  @args = parser.parse!(args)
end

Instance Method Details

#daemonizeObject

Public: Initialize the daemonized processing loop for Restforce::DB.

Returns nothing.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/restforce/db/command.rb', line 30

def daemonize
  dir = @options[:pid_dir]
  Dir.mkdir(dir) unless File.exist?(dir)

  daemon_args = {
    dir: dir,
    dir_mode: :normal,
    monitor: @monitor,
    ARGV: @args,
  }

  Restforce::DB::Worker.before_fork
  Daemons.run_proc("restforce-db", daemon_args) do |*_args|
    run @options
  end
end