-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
116 lines (88 loc) · 2.25 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# frozen_string_literal: true
require "rake/testtask"
MAILER_API_URL = ENV.fetch("MAILER_API_URL", nil)
MAILER_API_KEY = ENV.fetch("MAILER_API_KEY", nil)
ADMIN_EMAIL = ENV.fetch("ADMIN_EMAIL", nil)
SENDER_EMAIL = ENV.fetch("SENDER_EMAIL", nil)
SMTP_USER = ENV.fetch("SMTP_USER", nil)
SMTP_PASSWORD = ENV.fetch("SMTP_PASSWORD", nil)
SMTP_ADDRESS = ENV["SMTP_SERVER"] || ""
SMTP_PORT = ENV["SMTP_PORT"] || "587"
task default: [:test]
Rake::TestTask.new do |t|
t.pattern = "test/**/test_*.rb"
t.libs << "."
t.verbose = true
t.warning = false
end
namespace :db do
desc "Set up the database tables"
task :setup do
require_relative "db/schema"
end
end
desc "List all log entries"
task :logs do
require_relative "db/models"
puts Log.by_date.all
end
namespace :logs do
desc "List recent log entries"
task :recent do
require_relative "db/models"
puts Log.recent_by_date.all
end
desc "List log entries for failed requests"
task :errors do
require_relative "db/models"
puts Log.errors.by_date.all
end
desc "Cleanup logs"
task :cleanup do
require_relative "lib/mls/logcleaner"
require_relative "db/models"
MLS::LogCleaner.new.cleanup_all
end
end
desc "List all daily stats entries"
task :stats do
require_relative "db/models"
puts DailyStats.headers
puts DailyStats.by_date.all
end
namespace :mailer do
desc "List email service stats"
task :stats do
require_relative "lib/mls/mailerstats"
if MAILER_API_URL && MAILER_API_KEY
stats = MLS::MailerStats.new(
api_url: MAILER_API_URL,
api_key: MAILER_API_KEY
)
puts stats.get
else
warn "MAILER_API_URL or MAILER_API_KEY not defined"
end
end
desc "Test email delivery"
task :test do
require_relative "lib/mls/mailer"
if ADMIN_EMAIL
mailer = MLS::Mailer.new(
sender_email: SENDER_EMAIL,
smtp_user: SMTP_USER,
smtp_password: SMTP_PASSWORD,
smtp_address: SMTP_ADDRESS,
smtp_port: SMTP_PORT
)
mailer.mail(
to: ADMIN_EMAIL,
from: ADMIN_EMAIL,
subject: "Test email for ruby-lang-mls",
body: "This email has been sent with `rake mailer_test'."
)
else
warn "ADMIN_EMAIL not defined"
end
end
end