Skip to content

Commit

Permalink
Merge pull request #466 from UrLab/auto_close
Browse files Browse the repository at this point in the history
Auto close the space in the middle of the night
  • Loading branch information
Minigrim0 authored Oct 29, 2023
2 parents 159e7a5 + 1ebddc4 commit a9df731
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ services:
- db
networks:
- private
labels:
ofelia.enabled: "true"
ofelia.job-exec.autoclose.schedule: "0 0 4 * * *"
ofelia.job-exec.autoclose.command: "python3 manage.py close_space"
restart: unless-stopped

redis:
Expand Down Expand Up @@ -54,6 +58,13 @@ services:
- traefik-proxy
restart: unless-stopped

ofelia:
image: mcuadros/ofelia:latest
command: daemon --docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro


networks:
private:
driver: overlay
Expand Down
12 changes: 12 additions & 0 deletions incubator/management/commands/close_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.core.management.base import BaseCommand

from space.djredis import get_redis, set_space_open, space_is_open


class Command(BaseCommand):
help = "Closes the space automatically everyday at 4a.m."

def handle(self, *args, **options):
redis = get_redis()
if space_is_open(redis):
set_space_open(redis, False)
2 changes: 1 addition & 1 deletion space/djredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def set_space_open(client, is_open):
SpaceStatus.objects.create(is_open=bool(is_open))


def space_is_open(client):
def space_is_open(client) -> bool:
status = client.get('incubator_status')
return status is not None and int(status) == 1

Expand Down

0 comments on commit a9df731

Please sign in to comment.