mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-01 15:37:19 +00:00
feat: 全面修改 ansible 执行方式为 receptor (#12975)
* feat: 修复 receptor kill job 的问题 * feat: 全面修改 ansible 执行方式为 receptor --------- Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
@@ -23,6 +23,7 @@ from assets.models import Asset
|
||||
from assets.automations.base.manager import SSHTunnelManager
|
||||
from common.db.encoder import ModelJSONFieldEncoder
|
||||
from ops.ansible import JMSInventory, AdHocRunner, PlaybookRunner, CommandInBlackListException, UploadFileRunner
|
||||
from ops.ansible.receptor import receptor_runner
|
||||
from ops.mixin import PeriodTaskModelMixin
|
||||
from ops.variables import *
|
||||
from ops.const import Types, RunasPolicies, JobStatus, JobModules
|
||||
@@ -521,15 +522,16 @@ class JobExecution(JMSOrgBaseModel):
|
||||
ssh_tunnel.local_gateway_clean(runner)
|
||||
|
||||
def stop(self):
|
||||
from ops.signal_handlers import job_execution_stop_pub_sub
|
||||
|
||||
with open(os.path.join(self.private_dir, 'local.pid')) as f:
|
||||
try:
|
||||
pid = f.read()
|
||||
job_execution_stop_pub_sub.publish(int(pid))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.set_error('Job stop by "kill -9 {}"'.format(pid))
|
||||
unit_id_path = os.path.join(self.private_dir, "local.unitid")
|
||||
if os.path.exists(unit_id_path):
|
||||
with open(unit_id_path) as f:
|
||||
try:
|
||||
unit_id = f.read()
|
||||
receptor_runner.cancel(unit_id)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.set_error('Job stop by "receptor worker cancel, unit id is {}"'.format(unit_id))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Job Execution")
|
||||
|
Reference in New Issue
Block a user