-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
executable file
·150 lines (123 loc) · 3.54 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
# frozen_string_literal: true
require 'rake/testtask'
task :default do
puts `rake -T`
end
# Configuration only -- not for direct calls
task :config do
require_relative 'config/environment.rb' # load config info
@app = TaiGo::Api
@config = @app.config
end
desc 'Run tests once'
Rake::TestTask.new(:spec) do |t|
t.pattern = 'spec/*_spec.rb'
t.warning = false
end
task :console do
sh 'pry -r ./spec/test_load_all'
end
namespace :worker do
namespace :run do
desc 'Run the background cloning worker in development mode'
task :development => :config do
sh 'RACK_ENV=development bundle exec shoryuken -r ./workers/real_time_bus_worker.rb -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/real_time_bus_worker.rb -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/real_time_bus_worker.rb -C ./workers/shoryuken.yml'
end
end
end
namespace :vcr do
desc 'Delete cassette fixtures'
task :delete do
sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
puts(ok ? 'Cassettes deleted' : 'No cassettes found')
end
end
end
namespace :quality do
CODE = 'lib/'
desc 'run all quality checks'
task all: %i[rubocop reek flog]
task :rubocop do
sh 'rubocop'
end
task :reek do
sh "reek #{CODE}"
end
task :flog do
sh "flog #{CODE}"
end
end
namespace :queue do
require 'aws-sdk-sqs'
desc "Create SQS queue for Shoryuken"
task :create => :config do
sqs = Aws::SQS::Client.new(region: @config.AWS_REGION)
begin
queue = sqs.create_queue(
queue_name: @config.CLONE_QUEUE,
attributes: {
FifoQueue: 'true',
ContentBasedDeduplication: 'true'
}
)
q_url = sqs.get_queue_url(queue_name: @config.CLONE_QUEUE)
puts "Queue created:"
puts "Name: #{@config.CLONE_QUEUE}"
puts "Region: #{@config.AWS_REGION}"
puts "URL: #{q_url.queue_url}"
puts "Environment: #{@app.environment}"
rescue => e
puts "Error creating queue: #{e}"
end
end
desc "Purge messages in SQS queue for Shoryuken"
task :purge => :config do
sqs = Aws::SQS::Client.new(region: @config.AWS_REGION)
begin
queue = sqs.purge_queue(queue_url: @config.CLONE_QUEUE_URL)
puts "Queue #{@config.CLONE_QUEUE} purged"
rescue => e
puts "Error purging queue: #{e}"
end
end
end
namespace :db do
require_relative 'config/environment.rb' # load config info
require 'sequel' # TODO: remove after create orm
Sequel.extension :migration
app = TaiGo::Api
desc 'Run migrations'
task :migrate do
puts "Migrating #{app.environment} database to latest"
Sequel::Migrator.run(app.DB, 'infrastructure/database/migrations')
end
desc 'Drop all tables'
task :drop do
require_relative 'config/environment.rb'
# drop according to dependencies
app.DB.drop_table :stop_of_routes
app.DB.drop_table :sub_routes
app.DB.drop_table :routes
app.DB.drop_table :stops
app.DB.drop_table :schema_info
end
desc 'Reset all database tables'
task reset: %i[:drop :migrate]
desc 'Delete dev or test database file'
task :wipe do
if app.environment == :production
puts 'Cannot wipe production database!'
return
end
FileUtils.rm(app.config.DB_FILENAME)
puts "Deleted #{app.config.DB_FILENAME}"
end
end