-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
131 lines (104 loc) · 2.84 KB
/
Copy pathRakefile
File metadata and controls
131 lines (104 loc) · 2.84 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
123
124
125
126
127
128
129
130
131
require 'rake/testtask'
desc 'run tests'
Rake::TestTask.new(:spec) do |t|
t.pattern = 'spec/*_spec.rb'
t.warning = false
end
task :config do
require_relative 'config/environment.rb' # load config info
@app = WiKey::Api
@config = @app.config
ENV['AWS_ACCESS_KEY_ID'] = @config.AWS_ACCESS_KEY_ID
ENV['AWS_SECRET_ACCESS_KEY'] = @config.AWS_SECRET_ACCESS_KEY
ENV['AWS_REGION'] = @config.AWS_REGION
end
task :console do
sh 'ruby test.rb'
end
namespace :quality do
task :flog do
sh 'flog lib/'
end
task :reek do
sh 'reek lib/'
end
end
namespace :git do
task :log do
sh 'git log --graph --all'
end
task :add do
sh 'git add .'
end
end
namespace :db do
require_relative 'config/environment.rb'
require 'sequel'
Sequel.extension :migration
app = WiKey::Api
desc 'Run Migrations'
task :migrate do
puts "Migrating #{app.environment} database to lastest"
Sequel::Migrator.run(app.DB, 'infrastructure/database/migrations', allow_missing_migration_files: true)
end
desc "Prints current schema version"
task :version do
version = if app.DB.tables.include?(:schema_info)
app.DB[:schema_info].first[:version]
end || 0
puts "Schema Version: #{version}"
end
desc 'Drop all table'
task :drop do
require_relative 'config/environment.rb'
app.DB.drop_table :paragraphs
app.DB.drop_table :catalogs
app.DB.drop_table :topics
app.DB.drop_table :schema_info
end
desc 'Reset all database tables'
task reset: [: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
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.P_QUEUE,
attributes: {
FifoQueue: 'true',
ContentBasedDeduplication: 'true'
}
)
q_url = sqs.get_queue_url(queue_name: @config.P_QUEUE)
puts "Queue created:"
puts "Name: #{@config.P_QUEUE}"
puts "Region: #{@config.AWS_REGION}"
puts "URL: #{q_url.queue_url}"
puts "Environment: #{@app.environment}"
rescue Exception => e
puts e.to_s
end
end
end
namespace :worker do
namespace :run do
task :development => :config do
sh 'RACK_ENV=development bundle exec shoryuken -r ./workers/load_paragraphs_worker.rb -C ./workers/shoryuken_dev.yml'
end
task :test => :config do
sh 'RACK_ENV=test bundle exec shoryuken -r ./workers/load_paragraphs_worker.rb -C ./workers/shoryuken_test.yml'
end
end
end