feat: 修复 JOB 定时任务不执行的问题

pull/9510/head
Aaron3S 2 years ago
parent 564a87304c
commit 4daadbfa0a

@ -72,7 +72,7 @@ class JobExecutionViewSet(OrgBulkModelViewSet):
instance = serializer.save() instance = serializer.save()
instance.job_version = instance.job.version instance.job_version = instance.job.version
instance.material = instance.job.material instance.material = instance.job.material
instance.type = Types[instance.job.type].value instance.job_type = Types[instance.job.type].value
instance.creator = self.request.user instance.creator = self.request.user
instance.save() instance.save()
task = run_ops_job_execution.delay(instance.id) task = run_ops_job_execution.delay(instance.id)

@ -73,9 +73,9 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin):
return total_cost / finished_count if finished_count else 0 return total_cost / finished_count if finished_count else 0
def get_register_task(self): def get_register_task(self):
from ..tasks import run_ops_job_execution from ..tasks import run_ops_job
name = "run_ops_job_period_{}".format(str(self.id)[:8]) name = "run_ops_job_period_{}".format(str(self.id)[:8])
task = run_ops_job_execution.name task = run_ops_job.name
args = (str(self.id),) args = (str(self.id),)
kwargs = {} kwargs = {}
return name, task, args, kwargs return name, task, args, kwargs

@ -27,17 +27,18 @@ logger = get_logger(__file__)
@shared_task(soft_time_limit=60, queue="ansible", verbose_name=_("Run ansible task")) @shared_task(soft_time_limit=60, queue="ansible", verbose_name=_("Run ansible task"))
def run_ops_job(job_id): def run_ops_job(job_id):
job = get_object_or_none(Job, id=job_id) job = get_object_or_none(Job, id=job_id)
with tmp_to_org(job.org):
execution = job.create_execution() execution = job.create_execution()
run_ops_job_execution(execution) execution.creator = job.creator
run_ops_job_execution(execution.id)
try:
# execution.start()
# @shared_task(soft_time_limit=60, queue="ansible") except SoftTimeLimitExceeded:
# def show_env(): execution.set_error('Run timeout')
# import json logger.error("Run adhoc timeout")
# print(os.environ) except Exception as e:
# data = json.dumps(dict(os.environ), indent=4) execution.set_error(e)
# return data logger.error("Start adhoc execution error: {}".format(e))
@shared_task(soft_time_limit=60, queue="ansible", verbose_name=_("Run ansible task execution")) @shared_task(soft_time_limit=60, queue="ansible", verbose_name=_("Run ansible task execution"))

Loading…
Cancel
Save