-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rakefile
97 lines (81 loc) · 2.62 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
$LOAD_PATH.unshift '.'
# Create our application's ESPs
def processors(db_connection, tracker)
[
EventSourceryTodoApp::Projections::CompletedTodos::Projector.new(
tracker: tracker,
db_connection: db_connection,
),
EventSourceryTodoApp::Projections::OutstandingTodos::Projector.new(
tracker: tracker,
db_connection: db_connection,
),
EventSourceryTodoApp::Projections::ScheduledTodos::Projector.new(
tracker: tracker,
db_connection: db_connection,
),
EventSourceryTodoApp::Reactors::TodoCompletedNotifier.new(
tracker: tracker,
db_connection: db_connection,
)
]
end
task :environment do
require 'config/environment'
end
desc "Loads the project and starts Pry"
task console: :environment do
require 'pry'
Pry.start
end
desc 'Setup Event Stream Processors'
task setup_processors: :environment do
puts "Setting up Event Stream processors"
processors(EventSourceryTodoApp.projections_database, EventSourceryTodoApp.tracker).each(&:setup)
end
desc 'Run Event Stream Processors'
task run_processors: :environment do
puts "Starting Event Stream processors"
# Need to disconnect before starting the processors so
# that the forked processes have their own connection / fork safety.
EventSourceryTodoApp.projections_database.disconnect
# Show our ESP logs immediately under Foreman
$stdout.sync = true
esps = processors(EventSourceryTodoApp.projections_database, EventSourceryTodoApp.tracker)
# The ESPRunner will fork child processes for each of the ESPs passed to it.
EventSourcery::EventProcessing::ESPRunner.new(
event_processors: esps,
event_source: EventSourceryTodoApp.event_source,
).start!
end
namespace :db do
desc 'Create database'
task create: :environment do
url = EventSourceryTodoApp.config.database_url
database_name = File.basename(url)
database = Sequel.connect URI.join(url, '/template1').to_s
database.run(<<~DB_QUERY)
CREATE DATABASE #{database_name};
DB_QUERY
database.disconnect
end
desc 'Drop database'
task drop: :environment do
url = EventSourceryTodoApp.config.database_url
database_name = File.basename(url)
database = Sequel.connect URI.join(url, '/template1').to_s
database.run("DROP DATABASE IF EXISTS #{database_name}")
database.disconnect
end
desc 'Migrate database'
task migrate: :environment do
database = EventSourcery::Postgres.config.event_store_database
EventSourcery::Postgres::Schema.create_event_store(db: database)
end
end
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec
rescue LoadError
end