diff --git a/.vscode/launch.json b/.vscode/launch.json index ac399cc33425..745392455fa3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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": [ { @@ -93,6 +112,7 @@ "CVAT Server", "CVAT RQ - default", "CVAT RQ - low", + "CVAT git", ] } ] diff --git a/cvat/apps/git/git.py b/cvat/apps/git/git.py index 4f2769e6f4da..14780a09c163 100644 --- a/cvat/apps/git/git.py +++ b/cvat/apps/git/git.py @@ -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 @@ -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): diff --git a/cvat/apps/git/management/__init__.py b/cvat/apps/git/management/__init__.py new file mode 100644 index 000000000000..d89b5880c713 --- /dev/null +++ b/cvat/apps/git/management/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2018 Intel Corporation +# +# SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/cvat/apps/git/management/commands/__init__.py b/cvat/apps/git/management/commands/__init__.py new file mode 100644 index 000000000000..d89b5880c713 --- /dev/null +++ b/cvat/apps/git/management/commands/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2018 Intel Corporation +# +# SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/cvat/apps/git/management/commands/update_git_states.py b/cvat/apps/git/management/commands/update_git_states.py new file mode 100644 index 000000000000..6300005fef6b --- /dev/null +++ b/cvat/apps/git/management/commands/update_git_states.py @@ -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) + diff --git a/cvat/apps/git/migrations/0001_initial.py b/cvat/apps/git/migrations/0001_initial.py index e046a6d04299..10daa9c61e0b 100644 --- a/cvat/apps/git/migrations/0001_initial.py +++ b/cvat/apps/git/migrations/0001_initial.py @@ -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 diff --git a/supervisord.conf b/supervisord.conf index 2aa7f92fd203..c5af4c7657fc 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -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