Skip to content

Commit

Permalink
bugfix: 修复指定多配置模板检查时部分检查结果未展示的问题 (fixed TencentBlueKing#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Mar 22, 2023
1 parent 2cf85d7 commit 421dfb1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CodeCov
on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
env:
OS: ubuntu-18.04
OS: ubuntu-20.04
PYTHON: "3.6"
DJANGO_SETTINGS_MODULE: "settings"
DEBUG: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
permissions:
actions: read
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on: [push, pull_request]
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_1_push_rc_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
# 构建环境的Python版本
PYTHON_VERSION: "3.7"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_2_create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
# 构建环境的Python版本
PYTHON_VERSION: "3.7"
Expand Down
8 changes: 7 additions & 1 deletion apps/gsekit/job/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import List, Dict

from django.conf import settings
from django.db import models
from django.db import models, transaction
from django.db.models import QuerySet, Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -170,6 +170,12 @@ class JobTask(models.Model):
pipeline_id = models.CharField(_("PIPELINE ID"), max_length=33, db_index=True)
extra_data = models.JSONField(_("额外数据"), default=dict)

@classmethod
def set_status_by_id(cls, job_task_id: int, status, extra_data=None):
with transaction.atomic():
job_task = cls.objects.get(id=job_task_id)
job_task.set_status(status, extra_data)

def set_status(self, status, extra_data=None):
if extra_data is None:
extra_data = {}
Expand Down
22 changes: 16 additions & 6 deletions apps/gsekit/pipeline_plugins/components/collections/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from collections import defaultdict
from typing import List, Dict, Any, Optional, Set

from django.db import OperationalError
from django.db import OperationalError, transaction
from django.db.models import Max
from django.utils.translation import ugettext as _

Expand Down Expand Up @@ -987,13 +987,16 @@ def handle_succeeded_job_tasks(
config_inst_ids: List[int] = config_inst_ids_gby_job_task_id.get(job_task.id)
config_inst_id: int = config_inst_ids[0]
target_config_instance: Optional[Dict[str, Any]] = None
for config_instance in job_task.extra_data.get("config_instances") or []:
target_config_instance_index: Optional[int] = None
for index, config_instance in enumerate(job_task.extra_data.get("config_instances") or []):
if config_instance["id"] == config_inst_id:
target_config_instance_index = index
target_config_instance = config_instance
break

if not target_config_instance:
job_task.set_status(
JobTask.set_status_by_id(
job_task.id,
JobStatus.FAILED,
extra_data={
"err_code": exceptions.ConfigInstanceDoseNotExistException().code,
Expand All @@ -1004,7 +1007,8 @@ def handle_succeeded_job_tasks(

config_snapshot_content = job_instance_ip_log["log_content"]
if config_snapshot_content == "GSEKIT-404":
job_task.set_status(
JobTask.set_status_by_id(
job_task.id,
JobStatus.FAILED,
extra_data={
"err_code": exceptions.ConfigSnapshotDoseNotExistException().code,
Expand Down Expand Up @@ -1040,15 +1044,21 @@ def handle_succeeded_job_tasks(
}

if target_config_instance["sha256"] != sha256sum:
job_task.set_status(
JobTask.set_status_by_id(
job_task.id,
JobStatus.FAILED,
extra_data={
"err_code": exceptions.ConfigChangeException().code,
"failed_reason": _("现网配置与最近一次下发的配置不一致"),
},
)
else:
job_task.save(update_fields=["extra_data"])
with transaction.atomic():
newest_job_task: JobTask = JobTask.objects.get(id=job_task.id)
newest_job_task.extra_data["config_instances"][
target_config_instance_index
] = target_config_instance
job_task.save(update_fields=["extra_data"])

ConfigSnapshot.objects.bulk_create(to_be_created_config_snapshots)
ConfigSnapshot.objects.bulk_update(
Expand Down

0 comments on commit 421dfb1

Please sign in to comment.