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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. app_db.run('CREATE EXTENSION hstore')
  41. rescue Sequel::DatabaseError => e
  42. raise unless e.message.include?(
  43. "database \"#{ENV['DB_NAME']}\" already exists"
  44. )
  45. warn 'database already exists'
  46. end
  47. end
  48. desc 'Re Create Event Store datatabase and tables'
  49. task event_store: %i[environment event_sourcery] do
  50. database = EventSourcery::Postgres.config.event_store_database
  51. EventSourcery::Postgres::Schema.create_event_store(db: database)
  52. end
  53. desc 'Re Create Projections database and tables'
  54. task projections: %i[environment event_sourcery] do
  55. Hours::Projections::Nodes::Projector.new.setup
  56. end
  57. end