-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
305 lines (257 loc) · 7.48 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# frozen_string_literal: true
require 'rake/testtask'
require_relative 'require_app'
task :default do
puts `rake -T`
end
desc 'update daily government data'
task :update do
sh 'ruby app/data_init.rb'
end
namespace :spec do
desc 'Run unit and integration tests'
Rake::TestTask.new(:default) do |t|
# t.pattern = 'spec/tests/{unit}/*_spec.rb'
t.pattern = 'spec/tests/{integration,unit}/**/*_spec.rb'
# t.pattern = 'spec/tests/integration/layers/gateway_animal_spec.rb'
t.warning = false
end
desc 'Run unit, integration, and acceptance tests'
Rake::TestTask.new(:all) do |t|
t.pattern = 'spec/tests/**/*_spec.rb'
t.warning = false
end
end
namespace :another do
desc 'Run unit and integration tests'
Rake::TestTask.new(:domain) do |t|
t.pattern = 'spec/tests/{integration}/{domain}/*_spec.rb'
# t.pattern = 'spec/tests/{unit}/*_spec.rb'
# t.pattern = 'spec/tests/{integration,unit}/**/*_spec.rb'
# t.pattern = 'spec/tests/integration/layers/gateway_animal_spec.rb'
t.warning = false
end
end
desc 'Keep rerunning tests upon changes'
task :respec do
sh "rerun -c 'rake spec' --ignore 'coverage/*'"
end
desc 'Run web app in default mode'
task run: ['run:default']
namespace :run do
desc 'Run API in dev mode'
task :dev do
sh 'puma config.ru -p 9090'
end
desc 'Run API in test mode'
task :test do
sh 'puma config.ru -p 9090'
end
end
desc 'Keep rerunning web app upon changes'
task :rerun do
sh "rerun -c --ignore 'coverage/*' -- bundle exec puma"
end
desc 'Run application console'
task :console do
sh 'pry -r ./load_all'
end
namespace :vcr do
desc 'delete cassette fixtures'
task :wipe do
sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
puts(ok ? 'Cassettes deleted' : 'No cassettes found')
end
end
end
task :default do
puts `rake -T`
end
desc 'Run unit and integration tests'
Rake::TestTask.new(:spec) do |t|
t.pattern = 'spec/tests/**/*_spec.rb'
t.warning = false
end
desc 'Keep rerunning unit/integration tests upon changes'
task :respec do
sh "rerun -c 'rake spec' --ignore 'coverage/*' --ignore 'repostore/*'"
end
desc 'Run the webserver and application and restart if code changes'
task :rerun do
sh "rerun -c --ignore 'coverage/*' --ignore 'repostore/*' -- bundle exec puma"
end
desc 'Run web app in default (dev) mode'
task run: ['run:default']
namespace :run do
desc 'Run API in dev mode'
task :default do
sh 'rerun -c "bundle exec puma -p 9090"'
end
desc 'Run API in test mode'
task :test do
sh 'RACK_ENV=test bundle exec puma -p 9090'
end
end
namespace :db do
task :config do
require 'sequel'
require_relative 'config/environment' # load config info
require_relative 'spec/helpers/database_helper'
def app = PetAdoption::App
end
# daily update database
desc 'Run data initialization for database'
task :datainit => :config do
require_relative 'spec/helpers/init_database_data_helper'
require_app('infrastructure')
require_app('models')
puts 'puts all the data in the database'
# DatabaseHelper.wipe_database
Repository::App::PrepareDatabase.init_database
end
desc 'Run migrations'
task :migrate => :config do
Sequel.extension :migration
puts "Migrating #{app.environment} database to latest"
Sequel::Migrator.run(app.db, 'db/migrations')
end
desc 'Wipe records from all tables'
task :wipe => :config do
if app.environment == :production
puts 'Do not damage production database!'
return
end
require_app('infrastructure')
DatabaseHelper.wipe_database
end
desc 'Delete dev or test database file (set correct RACK_ENV)'
task :drop => :config do
if app.environment == :production
puts 'Do not damage production database!'
return
end
FileUtils.rm(PetAdoption::App.config.DB_FILENAME)
puts "Deleted #{PetAdoption::App.config.DB_FILENAME}"
end
end
namespace :vcr do
desc 'delete cassette fixtures'
task :wipe do
sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
puts(ok ? 'Cassettes deleted' : 'No cassettes found')
end
end
end
namespace :quality do
only_app = 'config/ app/'
desc 'run all static-analysis quality checks'
task all: %i[rubocop reek flog]
desc 'code style linter'
task :rubocop do
sh 'rubocop'
end
desc 'code smell detector'
task :reek do
sh 'reek'
end
desc 'complexiy analysis'
task :flog do
sh "flog -m #{only_app}"
end
end
namespace :cache do
task :config do
require_relative 'config/environment' # load config info
require_relative 'app/infrastructure/cache/redis_cache'
@api = PetAdoption::App
end
desc 'Directory listing of local dev cache'
namespace :list do
task :dev do
puts 'Lists development cache'
list = `ls _cache/rack/meta`
puts 'No local cache found' if list.empty?
puts list
end
desc 'Lists production cache'
task :production => :config do
puts 'Finding production cache'
keys = PetAdoption::Cache::RedisCache.new(@api.config).keys
puts 'No keys found' if keys.none?
keys.each { |key| puts "Key: #{key}" }
end
end
namespace :wipe do
desc 'Delete development cache'
task :dev do
puts 'Deleting development cache'
sh 'rm -rf _cache/*'
end
desc 'Delete production cache'
task :production => :config do
print 'Are you sure you wish to wipe the production cache? (y/n) '
if $stdin.gets.chomp.downcase == 'y'
puts 'Deleting production cache'
wiped = PetAdoption::Cache::RedisCache.new(@api.config).wipe
wiped.each { |key| puts "Wiped: #{key}" }
end
end
end
end
namespace :queues do
task :config do
require 'aws-sdk-sqs'
require_relative 'config/environment' # load config info
@api = PetAdoption::App
@sqs = Aws::SQS::Client.new(
access_key_id: @api.config.S3_Access_Key,
secret_access_key: @api.config.S3_Secret_Key,
region: @api.config.S3_Region
)
@q_name = @api.config.QUEUE_1
@q_url = @sqs.get_queue_url(queue_name: @q_name).queue_url
puts "Environment: #{@api.environment}"
end
desc 'Create SQS queue for worker'
task :create => :config do
@sqs.create_queue(queue_name: @q_name)
puts 'Queue created:'
puts " Name: #{@q_name}"
puts " Region: #{@api.config.AWS_REGION}"
puts " URL: #{@q_url}"
rescue StandardError => e
puts "Error creating queue: #{e}"
end
desc 'Report status of queue for worker'
task :status => :config do
puts 'Queue info:'
puts " Name: #{@q_name}"
puts " Region: #{@api.config.AWS_REGION}"
puts " URL: #{@q_url}"
rescue StandardError => e
puts "Error finding queue: #{e}"
end
desc 'Purge messages in SQS queue for worker'
task :purge => :config do
@sqs.purge_queue(queue_url: @q_url)
puts "Queue #{@q_name} purged"
rescue StandardError => e
puts "Error purging queue: #{e}"
end
end
namespace :worker do
namespace :run do
desc 'Run the background cloning worker in development mode'
task :dev => :config do
sh 'RACK_ENV=development bundle exec shoryuken -r ./workers -C ./workers/shoryuken_dev.yml'
end
desc 'Run the background cloning worker in testing mode'
task :test => :config do
sh 'RACK_ENV=test bundle exec shoryuken -r ./workers -C ./workers/shoryuken_test.yml'
end
desc 'Run the background cloning worker in production mode'
task :production => :config do
sh 'RACK_ENV=production bundle exec shoryuken -r ./workers -C ./workers/shoryuken.yml'
end
end
end