Skip to content

Commit

Permalink
Async server process for git updating
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Dec 11, 2018
1 parent 48551ef commit db161b8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
"env": {},
"envFile": "${workspaceFolder}/.env",
},
{
"name": "CVAT git",
"type": "python",
"request": "launch",
"debugStdLib": true,
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/manage.py",
"args": [
"update_git_states"
],
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
],
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
},
],
"compounds": [
{
Expand All @@ -93,6 +112,7 @@
"CVAT Server",
"CVAT RQ - default",
"CVAT RQ - low",
"CVAT git",
]
}
]
Expand Down
16 changes: 14 additions & 2 deletions cvat/apps/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils import timezone

from cvat.apps.engine.log import slogger
from cvat.apps.engine.models import Task, Job
from cvat.apps.engine.models import Task, Job, User
from cvat.apps.engine.annotation import _dump as dump, FORMAT_XML, save_job
from cvat.apps.engine.plugins import add_plugin

Expand Down Expand Up @@ -412,12 +412,24 @@ def get(tid, user):
except git.exc.GitCommandError as ex:
_have_no_access_exception(ex)
except Exception as ex:
db_git.status = 'error'
response['status']['error'] = str(ex)

db_git.check_date = timezone.now()
db_git.save()
return response

def update_states():
db_git_records = GitData.objects.all()
db_user = User.objects.first()
if db_user is None:
# User hasn't been created yet
return

for db_git in db_git_records:
try:
get(db_git.task_id, db_user)
except Exception:
slogger.glob("Exception occured during a status updating for db_git with tid: {}".format(db_git.task_id))

@transaction.atomic
def _onsave(jid, data):
Expand Down
3 changes: 3 additions & 0 deletions cvat/apps/git/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
3 changes: 3 additions & 0 deletions cvat/apps/git/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
21 changes: 21 additions & 0 deletions cvat/apps/git/management/commands/update_git_states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT

from django.core.management.base import BaseCommand, CommandError
from cvat.apps.git.git import update_states
import time

INTERVAL_SEC = 10

class Command(BaseCommand):
help = 'Run a regular updating for git status'

def handle(self, *args, **options):
while True:
try:
update_states()
except Exception:
pass
time.sleep(INTERVAL_SEC)

2 changes: 1 addition & 1 deletion cvat/apps/git/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1.3 on 2018-12-05 11:10
# Generated by Django 2.1.3 on 2018-12-05 13:24

from django.db import migrations, models
import django.db.models.deletion
Expand Down
5 changes: 5 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ command=%(ENV_HOME)s/wait-for-it.sh redis:6379 -t 0 -- bash -ic \
"exec /usr/bin/python3 %(ENV_HOME)s/manage.py rqworker -v 3 low"
numprocs=1

[program:rqworker_low]
command=%(ENV_HOME)s/wait-for-it.sh redis:6379 -t 0 -- bash -ic \
"/usr/bin/python3 ~/manage.py update_git_states"
numprocs=1

[program:runserver]
; Here need to run a couple of commands to initialize DB and copy static files.
; We cannot initialize DB on build because the DB should be online. Also some
Expand Down

0 comments on commit db161b8

Please sign in to comment.