Module: Dawn::CLI::App
- Extended by:
- Helpers
- Defined in:
- lib/dawn/cli/commands/app.rb
Class Method Summary collapse
-
.create(appname = nil) ⇒ Object
“Create a new dawn App (with git; setup)”.
-
.delete ⇒ Object
“Deletes the app on dawn”.
-
.list ⇒ Object
“Displays a list of all the apps you have deployed to dawn”.
-
.list_gears ⇒ Object
“Lists all currently running Gears”.
-
.logs(follow = false) ⇒ Object
“Prints the App’s log to STDOUT”.
- .restart ⇒ Object
-
.scale(modifiers) ⇒ Object
“Modify the gears of the current app”.
Methods included from Helpers
current_app, current_app_name, extract_app_in_dir, extract_app_remote_from_git_config, git, git_add_dawn_remote, git_dawn_remote?, git_remotes, git_remove_dawn_remote, has_git?, try_create_app
Methods included from OutputFormatter
#format_apps, #format_domains, #format_drains, #format_gears, #format_keys, #table_style
Class Method Details
.create(appname = nil) ⇒ Object
“Create a new dawn App (with git; setup)”
10 11 12 13 14 15 16 17 |
# File 'lib/dawn/cli/commands/app.rb', line 10 def self.create(appname=nil) app = try_create_app appname # since its possible for dawn to create a new app, with a random name # setting the appname again based on the real app's name is required appname = app.name git_add_dawn_remote app say "\tAPP\t#{app.name}" end |
.delete ⇒ Object
“Deletes the app on dawn”
47 48 49 50 51 52 |
# File 'lib/dawn/cli/commands/app.rb', line 47 def self.delete app = current_app app.destroy git_remove_dawn_remote app end |
.list ⇒ Object
“Displays a list of all the apps you have deployed to dawn”
20 21 22 |
# File 'lib/dawn/cli/commands/app.rb', line 20 def self.list say format_apps(Dawn::App.all) end |
.list_gears ⇒ Object
“Lists all currently running Gears”
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/dawn/cli/commands/app.rb', line 101 def self.list_gears app = current_app gears = app.gears.all.sort_by(&:number) ## Print all Gears gears_by_type = gears.each_with_object({}) do |gear, hsh| (hsh[gear.type] ||= []) << gear end gears_by_type.keys.sort.each do |key| grs = gears_by_type[key] say "=== #{key}:" say format_gears grs end end |
.logs(follow = false) ⇒ Object
“Prints the App’s log to STDOUT”
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dawn/cli/commands/app.rb', line 55 def self.logs(follow=false) # this is the only method which requires the uri & net/http require 'uri' require 'net/http' filter_regex = %r{\A(?<timestamp>\S+)\s(?<token>\S+)\[(?<proc_id>\S+)\]\:(?<message>.*)} = %r{(?<year>\d+)-(?<month>\d+)-(?<day>\d+)T(?<hour>\d+)\:(?<minute>\d+)\:(?<second>\d+)\.(?<other>.*)} opts = {} opts[:tail] = follow filters = args app = current_app url = app.logs(opts) uri = URI.parse(url) begin http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = 60 * 60 * 24 begin http.start do link_url = uri.path + ("?srv=1") #say uri.host + ":" + uri.port.to_s + link_url http.request_get(link_url) do |request| request.read_body do |chunk| if filters.size > 0 chunk.each_line do |line| if mtch_data = line.chomp.match(filter_regex) say mtch_data[0] if filters.include?(mtch_data[:proc_id]) end end else say chunk.to_s end end end end rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError raise "Could not connect to logging service" rescue Timeout::Error, EOFError raise "\nRequest timed out" end rescue Interrupt end end |
.restart ⇒ Object
116 117 118 |
# File 'lib/dawn/cli/commands/app.rb', line 116 def self.restart current_app.restart end |
.scale(modifiers) ⇒ Object
“Modify the gears of the current app”
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dawn/cli/commands/app.rb', line 25 def self.scale(modifiers) app = current_app #formation = app.formation.dup formation = {} modifiers.each do |type, a| operator, value = *a old_formation = (app.formation[type] || 0).to_i formation[type] = case operator when "+" then old_formation + value.to_i when "-" then old_formation - value.to_i when "=" then value.to_i end end app.scale(app: { formation: formation }) end |