Class: Pushpop::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/pushpop/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_optionsObject



9
10
11
# File 'lib/pushpop/cli.rb', line 9

def self.file_options
  option :file, :aliases => '-f'
end

Instance Method Details

#describe_jobsObject



26
27
28
29
30
31
32
33
34
# File 'lib/pushpop/cli.rb', line 26

def describe_jobs
  Dotenv.load
  Pushpop.require_file(options[:file])
  Pushpop.jobs.tap do |jobs|
    jobs.each do |job|
      puts job.name
    end
  end
end

#run_jobsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pushpop/cli.rb', line 50

def run_jobs
  Dotenv.load
  Pushpop.require_file(options[:file])
  Pushpop.schedule

  threads = []
  threads << Pushpop.start_clock

  Pushpop.web.app.traps = false
  web_thread = Pushpop.start_webserver
  threads << web_thread if web_thread

  # Listen to exit signals, so the CLI doesn't hang infinitely on clock
  [:INT, :TERM].each do |signal|
    trap(signal) do
      threads.each do |thread|
        thread.exit
      end
    end
  end

  # Wait for both the clock thread and the sinatra thread to close before exiting
  ThreadsWait.all_waits(threads) do
    threads.each do |thread|
      thread.exit
    end
  end
end

#run_jobs_onceObject



40
41
42
43
44
# File 'lib/pushpop/cli.rb', line 40

def run_jobs_once
  Dotenv.load
  Pushpop.require_file(options[:file])
  Pushpop.run
end

#versionObject



16
17
18
19
20
# File 'lib/pushpop/cli.rb', line 16

def version
  "Pushpop version #{Pushpop::VERSION}".tap do |s|
    puts s
  end
end