Skip to content

Commit

Permalink
feat: rework metrics
Browse files Browse the repository at this point in the history
feat: trigger restart on data validation
  • Loading branch information
xgui3783 committed Feb 29, 2024
1 parent 5c37f6b commit d135a48
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 193 deletions.
22 changes: 22 additions & 0 deletions .docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.0'
services:
api:
container_name: siibra-api
image: docker-registry.ebrains.eu/siibra/siibra-api:latest
ports:
- "5000:5000"
environment:
SIIBRA_CACHEDIR: /siibra-api-volume
SIIBRA_USE_CONFIGURATION: /siibra-configuration
volumes:
- ./siibra-api-volume:/siibra-api-volume
- ./siibra-configuration:/siibra-configuration
explorer:
container_name: siibra-explorer
image: docker-registry.ebrains.eu/siibra/siibra-explorer:staging
environment:
OVERWRITE_API_ENDPOINT: https://zam10189.zam.kfa-juelich.de/api/v3_0
EXPERIMENTAL_FLAG: '1'
HOST_PATHNAME: '/explorer'
ports:
- "8080:8080"
10 changes: 10 additions & 0 deletions .docker/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash

git -C ./siibra-configuration fetch && git -C ./siibra-configuration merge --ff-only origin/master

docker pull docker-registry.ebrains.eu/siibra/siibra-api:latest
docker pull docker-registry.ebrains.eu/siibra/siibra-explorer:staging

docker-compose down
sleep 5
docker-compose up -d
37 changes: 8 additions & 29 deletions .github/workflows/docker-img.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,14 @@ jobs:
secrets:
okd_token: ${{ secrets.OKD_PROD_SECRET }}

# disable deployment on jsc

# data-validation-config-hash:
# if: ${{ github.event_name == 'release' && contains(github.ref, 'rc') }}
# runs-on: ubuntu-latest
# outputs:
# CONFIG_SHORT_REV: ${{ steps.parse-rev.outputs.CONFIG_SHORT_REV }}
# steps:
# - id: parse-rev
# name: Get short rev of HEAD at master
# run: |
# git clone https://jugit.fz-juelich.de/t.dickscheid/brainscapes-configurations.git
# CONFIG_SHORT_REV=$(git -C brainscapes-configurations rev-parse --short=6 HEAD)
# echo CONFIG_SHORT_REV=$CONFIG_SHORT_REV >> $GITHUB_OUTPUT

# deploy-rc-on-data-validation:
# needs:
# - setup-envvar
# - data-validation-config-hash
# if: ${{ github.event_name == 'release' && contains(github.ref, 'rc') }}
# uses: ./.github/workflows/deploy-on-okd.yml
# with:
# okd_endpoint: https://okd.jsc.hbp.eu:443
# flavor: rc
# queues: ${{ needs.setup-envvar.outputs.queues }}
# version: c.${{ needs.data-validation-config-hash.outputs.CONFIG_SHORT_REV }}
# workerimage: docker-registry.ebrains.eu/siibra/siibra-api:rc-worker
# secrets:
# okd_token: ${{ secrets.OKD_JSC_SECRET }}
deploy-rc-on-data-validation:
needs:
- build-docker-img
if: ${{ github.event_name == 'push' }}
runs-on: siibra-data-validation
steps:
- run: |
/bin/bash -c "cd /softwares/software && ./restart.sh"
deploy-prod-on-okd:
needs: setup-envvar
Expand Down
40 changes: 40 additions & 0 deletions api/common/timer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from threading import Timer
from typing import List, Callable

class RepeatTimer(Timer):
"""RepeatTimer
Expand All @@ -8,3 +9,42 @@ class RepeatTimer(Timer):
def run(self):
while not self.finished.wait(self.interval):
self.function(*self.args, **self.kwargs)

class Cron:
def __init__(self) -> None:
self._minutely_fns: List[Callable] = []
self._ten_minutely_fns: List[Callable] = []

self._timers: List[RepeatTimer] = [
RepeatTimer(60, self._run_minutely),
RepeatTimer(600, self._run_ten_minutely)
]

def _run_minutely(self):
for fn in self._minutely_fns:
fn()

def _run_ten_minutely(self):
for fn in self._ten_minutely_fns:
fn()

def minutely(self, fn: Callable):
self._minutely_fns.append(fn)
return fn

def ten_minutely(self, fn: Callable):
self._ten_minutely_fns.append(fn)
return fn

def run_all(self):
self._run_ten_minutely()
self._run_minutely()

def start(self):
for timer in self._timers:
timer.start()

def stop(self):
"""On terminate"""
for timer in self._timers:
timer.cancel()
Loading

0 comments on commit d135a48

Please sign in to comment.