⌚ OpenOpeningstijden main server application
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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