⌚ 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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. $LOAD_PATH.unshift '.'
  3. require 'dotenv/load'
  4. task :event_sourcery do
  5. require 'config/event_sourcery.rb'
  6. end
  7. task :environment do
  8. require 'lib/hours'
  9. end
  10. desc 'Setup Event Stream Processors'
  11. task setup_processors: :environment do
  12. Hours::Projections::Nodes::Projector.new.setup
  13. end
  14. desc 'Run Event Stream Processors'
  15. task run_processors: :environment do
  16. # Need to disconnect before starting the processors so
  17. # that the forked processes have their own connection / fork safety.
  18. Hours.projections_database.disconnect
  19. esps = [
  20. Hours::Projections::Nodes::Projector.new
  21. ]
  22. # The ESPRunner will fork child processes for each of the ESPs passed to it.
  23. EventSourcery::EventProcessing::ESPRunner.new(
  24. event_processors: esps,
  25. event_source: Hours.event_source
  26. ).start!
  27. end
  28. desc 'Run webserver'
  29. task run_web: :environment do
  30. sh %(bundle exec rackup -p #{ENV['PORT'] || 9292})
  31. end
  32. namespace :db do
  33. task create: :environment do
  34. pg_db = Sequel.connect(Hours.config.postgres_database_url)
  35. begin
  36. pg_db.run("CREATE DATABASE #{ENV['DB_NAME']}")
  37. pg_db.disconnect
  38. app_db = Sequel.connect(Hours.config.database_url)
  39. app_db.run('CREATE EXTENSION postgis')
  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