Module: Postqueue::CLI
- Extended by:
- CLI
- Included in:
- CLI
- Defined in:
- lib/postqueue/cli.rb,
lib/postqueue/cli/stats.rb,
lib/postqueue/cli/options_parser.rb
Defined Under Namespace
Modules: Stats
Classes: OptionsParser
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/postqueue/cli.rb', line 10
def options
@options
end
|
Instance Method Details
#active_record_config ⇒ Object
49
50
51
52
53
54
|
# File 'lib/postqueue/cli.rb', line 49
def active_record_config
require "yaml"
database_config = YAML.load_file "config/database.yml"
env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
database_config.fetch(env)
end
|
#connect_to_database! ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/postqueue/cli.rb', line 41
def connect_to_database!
abc = active_record_config
username, host, database = abc.values_at "username", "host", "database"
Postqueue.logger.info "Connecting to postgres:#{username}@#{host}/#{database}"
ActiveRecord::Base.establish_connection(abc)
end
|
#connect_to_rails! ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/postqueue/cli.rb', line 32
def connect_to_rails!
if File.exist?("config/environment.rb")
load "config/environment.rb"
else
logger.warn "Trying to load postqueue configuration from config/postqueue.rb"
load "config/postqueue.rb"
end
end
|
#run(argv) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/postqueue/cli.rb', line 12
def run(argv)
@options = OptionsParser.parse_args(argv)
case options.sub_command
when "stats", "peek"
connect_to_database!
Stats.send options.sub_command, options
when "enqueue"
connect_to_database!
count = Postqueue.enqueue op: options.op, entity_id: options.entity_ids
Postqueue.logger.info "Enqueued #{count} queue items"
when "process"
connect_to_rails!
Postqueue.process batch_size: 1
when "run"
connect_to_rails!
Postqueue.run!
end
end
|