-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
122 lines (108 loc) · 3.14 KB
/
Rakefile
File metadata and controls
122 lines (108 loc) · 3.14 KB
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
# frozen_string_literal: true
require 'rake/testtask'
task :default do
puts `rake -T`
end
Rake::TestTask.new(:spec) do |t|
t.pattern = 'spec/*_spec.rb'
t.warning = false
end
namespace :run do
task :dev do
sh 'rerun "rackup -p 9292"'
end
task :test do
loop do
puts 'Setting up test environment'
ENV['RACK_ENV'] = 'test'
Rake::Task['db:_setup'].execute
Rake::Task['db:reset'].execute
puts 'Populating test database'
url_request = { city: 'Taipei', country_code: 'TW' }
LoadCityFromMeetup.call(url_request.to_json)
sh 'rerun "rackup -p 3000"'
end
end
end
namespace :db do
task :_setup do
require 'sequel'
require_relative 'init'
Sequel.extension :migration
end
desc 'Run database migrations'
task migrate: [:_setup] do
puts "Migrating to latest for: #{ENV['RACK_ENV'] || 'development'}"
Sequel::Migrator.run(DB, 'db/migrations')
Rake::Task['db:schema'].execute
end
desc 'Reset migrations (full rollback and migration)'
task reset: [:_setup] do
puts "Rolling back #{ENV['RACK_ENV'] || 'development'} database"
Sequel::Migrator.run(DB, 'db/migrations', target: 0)
Rake::Task['db:migrate'].execute
end
desc 'Print out final schema to file'
task schema: [:_setup] do
DB.extension :schema_dumper
File.open('db/schema.rb', 'w') do |file|
header = <<~END
# This schema file is automatically generated by `rake db:schema`.
# It will be overwritten periodically so do not make changes.
END
puts 'Writing schema to db/schema.rb'
file.write(header)
file.write(DB.dump_schema_migration)
end
end
end
desc 'delete cassette fixtures'
task :wipe do
sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
puts(ok ? 'Cassettes deleted' : 'No casseettes found')
end
end
namespace :quality do
CODE = 'app.rb'
desc 'run all quality checks'
task all: [:rubocop, :flog, :flay]
task :flog do
sh "flog #{CODE}"
end
task :flay do
sh "flay #{CODE}"
end
task :rubocop do
sh 'rubocop'
end
end
namespace :queue do
require 'aws-sdk'
require_relative 'init'
desc "Create SQS queue for Shoryuken"
task :create do
config = EventsLocatorAPI.config
sqs = Aws::SQS::Client.new(region: config.AWS_REGION,
access_key_id: config.AWS_ACCESS_KEY_ID,
secret_access_key: config.AWS_SECRET_ACCESS_KEY)
begin
queue = sqs.create_queue(queue_name: config.NEW_CITY_QUEUE)
puts "Queue #{config.NEW_CITY_QUEUE} created on #{config.AWS_REGION}"
rescue => e
puts "Error creating queue: #{e}"
end
end
task :purge do
config = FaceGroupAPI.config
sqs = Aws::SQS::Client.new(region: config.AWS_REGION,
access_key_id: config.AWS_ACCESS_KEY_ID,
secret_access_key: config.AWS_SECRET_ACCESS_KEY)
begin
url = sqs.get_queue_url({ queue_name: config.NEW_CITY_QUEUE })
queue = sqs.purge_queue({ queue_url: url.queue_url})
puts "Queue #{config.NEW_CITY_QUEUE} purged"
rescue => e
puts "Error purging queue: #{e}"
end
end
end