⌚ 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.2KB

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