Mirror of Github Repo. https://github.com/flockingbird/roost
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Rakefile 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. $LOAD_PATH.unshift '.'
  3. task :environment do
  4. require 'config/environment'
  5. end
  6. task :database do
  7. require 'config/database'
  8. end
  9. desc 'Run Event Stream Processors'
  10. task run_processors: %i[environment database] do
  11. puts 'Starting Event Stream processors'
  12. event_source = Roost.event_source
  13. tracker = Roost.tracker
  14. db_connection = Roost.projections_database
  15. # Need to disconnect before starting the processors
  16. # to ensure each forked process has its own connection
  17. db_connection.disconnect
  18. # Show our ESP logs in foreman immediately
  19. $stdout.sync = true
  20. processors = Roost.all_processors.map do |processor_class|
  21. processor_class.new(tracker: tracker, db_connection: db_connection)
  22. end
  23. EventSourcery::EventProcessing::ESPRunner.new(
  24. event_processors: processors,
  25. event_source: event_source
  26. ).start!
  27. end
  28. namespace :db do
  29. desc 'Create database'
  30. task create: :environment do
  31. begin
  32. database.run("CREATE DATABASE #{database_name}")
  33. rescue StandardError => e
  34. puts "Could not create database '#{database_name}': #{e.class.name}"\
  35. "#{e.message}"
  36. end
  37. database.disconnect
  38. end
  39. desc 'Drop database'
  40. task drop: :environment do
  41. database.run("DROP DATABASE IF EXISTS #{database_name}")
  42. database.disconnect
  43. end
  44. desc 'Migrate database'
  45. task migrate: %i[environment database] do
  46. database = EventSourcery::Postgres.config.event_store_database
  47. begin
  48. EventSourcery::Postgres::Schema.create_event_store(db: database)
  49. rescue StandardError => e
  50. puts "Could not create event store: #{e.class.name} #{e.message}"
  51. end
  52. end
  53. desc 'Setup Event Stream projections'
  54. task create_projections: %i[environment database] do
  55. Roost.all_processors.map(&:new).each(&:setup)
  56. end
  57. desc 'Reset Event Stream projections'
  58. task reset_projections: %i[environment database] do
  59. Roost.all_processors.map(&:new).each(&:reset)
  60. end
  61. def database
  62. Sequel.connect URI.join(url, '/template1').to_s
  63. end
  64. def database_name
  65. File.basename(url)
  66. end
  67. def url
  68. Roost.config.database_url
  69. end
  70. end