perf: 持续优化作业创建

This commit is contained in:
Aaron3S
2022-12-02 12:21:56 +08:00
parent 21f91358cf
commit 6d0545f04f
12 changed files with 820 additions and 630 deletions

View File

@@ -136,7 +136,7 @@ class JobExecution(JMSOrgBaseModel):
)
elif self.job.type == 'playbook':
runner = PlaybookRunner(
self.inventory_path, self.job.playbook.work_path
self.inventory_path, self.job.playbook.entry
)
else:
raise Exception("unsupported job type")

View File

@@ -5,6 +5,7 @@ from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from ops.exception import PlaybookNoValidEntry
from orgs.mixins.models import JMSOrgBaseModel
@@ -16,5 +17,10 @@ class Playbook(JMSOrgBaseModel):
comment = models.CharField(max_length=1024, default='', verbose_name=_('Comment'), null=True, blank=True)
@property
def work_path(self):
return os.path.join(settings.DATA_DIR, "ops", "playbook", self.id.__str__(), "main.yaml")
def entry(self):
work_dir = os.path.join(settings.DATA_DIR, "ops", "playbook", self.id.__str__())
valid_entry = ('main.yml', 'main.yaml', 'main')
for f in os.listdir(work_dir):
if f in valid_entry:
return os.path.join(work_dir, f)
raise PlaybookNoValidEntry