⌚ OpenOpeningstijden main server application
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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # frozen_string_literal: true
  2. $LOAD_PATH.unshift '.'
  3. def production?
  4. ENV['APP_ENV'] == 'production'
  5. end
  6. def projectors
  7. [
  8. Hours::Projections::Places::Projector.new,
  9. Hours::Projections::Addresses::Projector.new,
  10. Hours::Projections::Regions::Projector.new
  11. ]
  12. end
  13. task :environment do
  14. require 'lib/hours'
  15. end
  16. task :sequel do
  17. unless production?
  18. require 'dotenv'
  19. Dotenv.load(".env.#{ENV['APP_ENV']}", '.env')
  20. end
  21. require 'sequel'
  22. require 'sequel-postgis-georuby'
  23. @pg_url = "postgres://#{ENV['DB_USER']}:#{ENV['DB_PASSWORD']}@"\
  24. "#{ENV['DB_HOST']}:#{ENV['DB_PORT']}"
  25. end
  26. desc 'Setup Event Stream Processors'
  27. task setup_processors: :environment do
  28. Hours::Projections::Places::Projector.new.setup
  29. end
  30. desc 'Run Event Stream Processors'
  31. task run_processors: :environment do
  32. # Need to disconnect before starting the
  33. # processors so that the forked processes have their own connection / fork
  34. # safety.
  35. Hours.projections_database.disconnect
  36. # The ESPRunner will fork child processes for each of the ESPs passed to it.
  37. EventSourcery::EventProcessing::ESPRunner.new(
  38. event_processors: projectors,
  39. event_source: Hours.event_source
  40. ).start!
  41. end
  42. desc 'Run webserver'
  43. task run_web: :environment do
  44. sh %(bundle exec rackup -p #{ENV['PORT'] || 9292})
  45. end
  46. namespace :db do
  47. task create: :sequel do
  48. pg_db = Sequel.connect("#{@pg_url}/postgres")
  49. begin
  50. pg_db.run("CREATE DATABASE #{ENV['DB_NAME']}")
  51. pg_db.disconnect
  52. app_db = Sequel.connect("#{@pg_url}/#{ENV['DB_NAME']}")
  53. app_db.run('CREATE EXTENSION postgis')
  54. app_db.run('CREATE EXTENSION hstore')
  55. rescue Sequel::DatabaseError => e
  56. raise unless e.message.include?(
  57. "database \"#{ENV['DB_NAME']}\" already exists"
  58. )
  59. warn 'database already exists'
  60. end
  61. end
  62. desc 'Create Event Store datatabase and tables'
  63. task event_store: :environment do
  64. database = EventSourcery::Postgres.config.event_store_database
  65. EventSourcery::Postgres::Schema.create_event_store(db: database)
  66. end
  67. desc 'Create Projections database and tables'
  68. task(projections: :environment) { projectors.each(&:setup) }
  69. desc 'Reset Projections'
  70. task(reset: :environment) { projectors.each(&:reset) }
  71. end
  72. namespace :db do
  73. task seed: :environment do
  74. require_relative 'test/support/data_helpers.rb'
  75. Dir['./test/support/workflows/*.rb'].each { |file| require file }
  76. include DataHelpers
  77. include Workflows::AddPlace
  78. events.each do |event|
  79. puts event
  80. projector.process(event)
  81. end
  82. end
  83. end