Added service shard integration
This commit is contained in:
parent
bcc8db2004
commit
dd1e5e78ea
12 changed files with 101 additions and 147 deletions
|
@ -108,6 +108,10 @@ shards:
|
||||||
git: https://github.com/spider-gazelle/secrets-env.git
|
git: https://github.com/spider-gazelle/secrets-env.git
|
||||||
version: 1.3.1
|
version: 1.3.1
|
||||||
|
|
||||||
|
service:
|
||||||
|
git: https://git.dergrimm.net/dergrimm/service.git
|
||||||
|
version: 0.1.0+git.commit.b1e449572cffc80afa0ceb518590591d4f9c5bed
|
||||||
|
|
||||||
shard:
|
shard:
|
||||||
git: https://github.com/maiha/shard.cr.git
|
git: https://github.com/maiha/shard.cr.git
|
||||||
version: 0.3.1
|
version: 0.3.1
|
||||||
|
|
|
@ -66,3 +66,5 @@ dependencies:
|
||||||
github: maiha/shard.cr
|
github: maiha/shard.cr
|
||||||
retriable:
|
retriable:
|
||||||
github: Sija/retriable.cr
|
github: Sija/retriable.cr
|
||||||
|
service:
|
||||||
|
git: https://git.dergrimm.net/dergrimm/service.git
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
require "retriable/core_ext/kernel"
|
|
||||||
|
|
||||||
require "./backend/*"
|
require "./backend/*"
|
||||||
|
|
||||||
# Base module
|
# Base module
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require "./api/service"
|
||||||
require "./api/*"
|
require "./api/*"
|
||||||
|
|
||||||
# Api module
|
# Api module
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
||||||
# Copyright (C) 2022 Dominic Grimm
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
require "http/server"
|
|
||||||
|
|
||||||
module Backend
|
|
||||||
module Api
|
|
||||||
extend self
|
|
||||||
|
|
||||||
# Runs API
|
|
||||||
def run : Nil
|
|
||||||
WebServer.new.run
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -14,13 +14,23 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require "service"
|
||||||
|
require "log"
|
||||||
|
|
||||||
module Backend
|
module Backend
|
||||||
module Api
|
module Api
|
||||||
# Api service
|
# API service
|
||||||
SERVICE = ->do
|
class Service < ::Service
|
||||||
Log.info { "Starting Api service..." }
|
Log = ::Log.for(self)
|
||||||
run
|
|
||||||
Log.info { "Api service stopped." }
|
# Runs API service
|
||||||
|
def run(_unit : ::Service::Unit) : ::Service::Unit?
|
||||||
|
Log.info { "Starting Api service..." }
|
||||||
|
WebServer.new.run
|
||||||
|
Log.info { "Api service stopped." }
|
||||||
|
|
||||||
|
::Service::Unit.new(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
||||||
# Copyright (C) 2022 Dominic Grimm
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
module Backend
|
|
||||||
extend self
|
|
||||||
|
|
||||||
# Runs backend services
|
|
||||||
def run : Nil
|
|
||||||
{% if flag?(:development) %}
|
|
||||||
Log.warn { "Backend is running in development mode! Do not use this in production!" }
|
|
||||||
{% end %}
|
|
||||||
|
|
||||||
Log.info { "Checking if DB schema is up to date..." }
|
|
||||||
retry(backoff: false, base_interval: 10.seconds, multiplier: 1.0) do
|
|
||||||
case retry(on: DB::ConnectionRefused, backoff: false) do
|
|
||||||
Db.schema_up_to_date_compare
|
|
||||||
end
|
|
||||||
when nil
|
|
||||||
Log.fatal { "No database schema is applied. Please run `bash scripts/micrate.sh up` urgently!" }
|
|
||||||
raise Exception.new
|
|
||||||
when -1
|
|
||||||
Log.warn { "Database schema is not up to date. Please run `bash scripts/micrate.sh up`." }
|
|
||||||
when 0
|
|
||||||
Log.info { "Database schema is up to date." }
|
|
||||||
else
|
|
||||||
Log.warn { "Database schema is maybe up to date but not consistent. Please run `bash scripts/micrate.sh up` to be safe." }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Log.info { "Starting services..." }
|
|
||||||
channel = Channel(Nil).new(SERVICES.size)
|
|
||||||
SERVICES.each do |service|
|
|
||||||
spawn do
|
|
||||||
service.call
|
|
||||||
channel.send(nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
SERVICES.size.times do
|
|
||||||
channel.receive
|
|
||||||
end
|
|
||||||
Fiber.yield
|
|
||||||
|
|
||||||
Log.info { "Backend services started." }
|
|
||||||
end
|
|
||||||
end
|
|
64
docker/backend/src/backend/runner.cr
Normal file
64
docker/backend/src/backend/runner.cr
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
||||||
|
# Copyright (C) 2022 Dominic Grimm
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require "service"
|
||||||
|
require "log"
|
||||||
|
require "retriable"
|
||||||
|
|
||||||
|
module Backend
|
||||||
|
# Backend runner
|
||||||
|
class Runner < Service::Runner
|
||||||
|
Log = ::Log.for(self)
|
||||||
|
|
||||||
|
# Service starters
|
||||||
|
def starters : Array(Service::Starter)
|
||||||
|
[
|
||||||
|
Service::SynchronousStarter.new([
|
||||||
|
Api::Service.new.as(Service),
|
||||||
|
Worker::Service.new.as(Service),
|
||||||
|
] of Service).as(Service::Starter),
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run the backend
|
||||||
|
def run : self
|
||||||
|
{% if flag?(:development) %}
|
||||||
|
Log.warn { "Backend is running in development mode! Do not use this in production!" }
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
Log.info { "Checking if DB schema is up to date..." }
|
||||||
|
Retriable.retry(backoff: false, base_interval: 10.seconds, multiplier: 1.0) do
|
||||||
|
case Retriable.retry(on: DB::ConnectionRefused, backoff: false) do
|
||||||
|
Db.schema_up_to_date_compare
|
||||||
|
end
|
||||||
|
when nil
|
||||||
|
Log.fatal { "No database schema is applied. Please run `bash scripts/micrate.sh up` urgently!" }
|
||||||
|
raise Exception.new
|
||||||
|
when -1
|
||||||
|
Log.warn { "Database schema is not up to date. Please run `bash scripts/micrate.sh up`." }
|
||||||
|
when 0
|
||||||
|
Log.info { "Database schema is up to date." }
|
||||||
|
else
|
||||||
|
Log.warn { "Database schema is maybe up to date but not consistent. Please run `bash scripts/micrate.sh up` to be safe." }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Log.info { "Starting services..." }
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,23 +0,0 @@
|
||||||
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
||||||
# Copyright (C) 2022 Dominic Grimm
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
module Backend
|
|
||||||
# Backend services to be included in the application
|
|
||||||
SERVICES = [
|
|
||||||
Api::SERVICE,
|
|
||||||
Worker::SERVICE,
|
|
||||||
]
|
|
||||||
end
|
|
|
@ -1,26 +0,0 @@
|
||||||
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
||||||
# Copyright (C) 2022 Dominic Grimm
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
module Backend
|
|
||||||
module Worker
|
|
||||||
extend self
|
|
||||||
|
|
||||||
# Runs the worker
|
|
||||||
def run : Nil
|
|
||||||
Mosquito::Runner.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -14,13 +14,23 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require "service"
|
||||||
|
require "log"
|
||||||
|
|
||||||
module Backend
|
module Backend
|
||||||
module Worker
|
module Worker
|
||||||
# Worker service
|
# Worker service
|
||||||
SERVICE = ->do
|
class Service < ::Service
|
||||||
Log.info { "Starting worker service..." }
|
Log = ::Log.for(self)
|
||||||
run
|
|
||||||
Log.info { "Worker service stopped." }
|
# Runs worker service
|
||||||
|
def run(_unit : ::Service::Unit) : ::Service::Unit?
|
||||||
|
Log.info { "Starting worker service..." }
|
||||||
|
Mosquito::Runner.start
|
||||||
|
Log.info { "Worker service stopped." }
|
||||||
|
|
||||||
|
::Service::Unit.new(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,7 +61,7 @@ cli = Commander::Command.new do |cmd|
|
||||||
c.long = c.short
|
c.long = c.short
|
||||||
|
|
||||||
c.run do
|
c.run do
|
||||||
Backend.run
|
Backend::Runner.new.run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue