Module: Harbr

Defined in:
lib/harbr.rb,
lib/harbr/host.rb,
lib/harbr/version.rb,
lib/harbr/container.rb

Overview

Harbr module for managing containers, jobs, ports, and 2s

Defined Under Namespace

Modules: SSH Classes: Container, Error, Host

Constant Summary collapse

DEFAULT_DIRECTORY =
"~/.config/harbr"
DEFAULT_DIRECTORY_DATA_DIR =
"#{DEFAULT_DIRECTORY}/.data"
VERSION =
"2.8.1"

Class Method Summary collapse

Class Method Details

.notifiable(name, version, env) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/harbr.rb', line 66

def self.notifiable(name, version, env)
  yield if block_given?
  send_notification("Harbr: #{name} deployed to #{env} successfully", "<p>harbr: #{version} of #{name} deployed to #{env} successfully</p>")
rescue => e
  html_content = <<~HTML
    <p>Error: #{e.message}</p>
              <p>#{e.backtrace.join("<br>")}</p>
              <p>harbr: #{version} of #{env} #{name} failed to deploy</p>
  HTML

  send_notification("Harbr: #{name} failed to deploy", html_content)
end

.send_notification(subject, body) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/harbr.rb', line 45

def self.send_notification(subject, body)
  resend_config = YAML.load_file("/etc/harbr/resend.yml")

  Resend.api_key = resend_config["key"]

  params = {
    from: resend_config["from"],
    to: resend_config["to"],
    subject: subject,
    html: body
  }

  puts "Sending notification: #{params}"

  Resend::Emails.send(params)
rescue => e
  puts "Error: #{e.class}"
  puts "backtrace: #{e.backtrace.join('\n')}"
  puts "Error sending notification: #{e.message}"
end