fix: centralize native dispatch and itemize retained session release
This commit is contained in:
1 parent
60101b7195
commit
306aa5c544
4 files changed
+149
-29
No files matched your search
@@ -835,10 +835,11 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
_write_json(root/'native-add-log-baseline.json', log_baseline)
|
||||
observed_failures = {}
|
||||
_require_add_supervisor(job, root)
|
||||
from .session_record import update_worker_state
|
||||
update_worker_state(job, 'NATIVE_CALL', required=True)
|
||||
job['_native_add_pending'] = True
|
||||
win32gui.PostMessage(ok, win32con.BM_CLICK, 0, 0)
|
||||
from .session_record import dispatch_native, update_worker_state
|
||||
def submit_add():
|
||||
job['_native_add_pending'] = True
|
||||
win32gui.PostMessage(ok, win32con.BM_CLICK, 0, 0)
|
||||
dispatch_native(job, submit_add, asynchronous=True, required=True)
|
||||
success = None
|
||||
while time.monotonic() < deadline:
|
||||
pythoncom.PumpWaitingMessages()
|
||||
@@ -1106,9 +1107,10 @@ def _catalog_com(job, root):
|
||||
watcher = None
|
||||
try:
|
||||
_require_management_continuation(job, root)
|
||||
from .session_record import update_worker_state
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
app = win32com.client.DispatchEx('LibraryManager.Application')
|
||||
from .session_record import dispatch_native, update_worker_state
|
||||
# Keep the launch pending until its exact native identity is recorded.
|
||||
app = dispatch_native(job, lambda: win32com.client.DispatchEx('LibraryManager.Application'),
|
||||
asynchronous=True)
|
||||
app.Visible = True
|
||||
processes = _process_details('LibraryManager.exe')
|
||||
owned_pids.update(int(p[0]) for p in processes)
|
||||
@@ -1124,15 +1126,14 @@ def _catalog_com(job, root):
|
||||
if job['operation'] in ('probe_create_add', 'probe_create'):
|
||||
target = prepare_probe_library(job, root)
|
||||
_require_management_continuation(job, root)
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
library = app.CreateLibrary(str(target), 1)
|
||||
library = dispatch_native(job, lambda: app.CreateLibrary(str(target), 1), asynchronous=True)
|
||||
_write_json(root.parent/'probe-owner.json', {'library': str(target), 'token': job['probe_token']})
|
||||
else:
|
||||
if job['operation'] == 'probe_readd':
|
||||
validate_probe_readd(job, root)
|
||||
_require_management_continuation(job, root)
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
library = app.OpenLibrary(str(absolute_preserving_drive(job['library'])))
|
||||
library = dispatch_native(job, lambda: app.OpenLibrary(str(absolute_preserving_drive(job['library']))),
|
||||
asynchronous=True)
|
||||
update_worker_state(job, 'POSTCALL')
|
||||
if refused:
|
||||
raise RuntimeError('目录读取需要升级中心库或选择流程;已拒绝,目标未获准自动升级。')
|
||||
@@ -1142,12 +1143,10 @@ def _catalog_com(job, root):
|
||||
if int(library.FlowType) != 1:
|
||||
raise RuntimeError('Native Add requires the DxDesigner Logical-Physical library flow.')
|
||||
_probe_add_dialog(app, job, desktop, owned_pids, root, library=library)
|
||||
update_worker_state(job, 'CLOSING')
|
||||
library.Close()
|
||||
dispatch_native(job, lambda: library.Close(), phase='CLOSING')
|
||||
library = None
|
||||
_require_management_continuation(job, root)
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
library = app.OpenLibrary(str(absolute_preserving_drive(job['library'])))
|
||||
library = dispatch_native(job, lambda: app.OpenLibrary(str(absolute_preserving_drive(job['library']))))
|
||||
if (library is None or Path(str(library.FullName)).resolve() != Path(job['library']).resolve()
|
||||
or int(library.FlowType) != 1):
|
||||
raise RuntimeError('Native Add reopen did not confirm the exact library and flow.')
|
||||
@@ -1189,16 +1188,14 @@ def _catalog_com(job, root):
|
||||
finally:
|
||||
if library is not None and not job.get('_native_add_pending'):
|
||||
try:
|
||||
update_worker_state(job, 'CLOSING')
|
||||
library.Close()
|
||||
dispatch_native(job, lambda: library.Close(), phase='CLOSING')
|
||||
except Exception as error:
|
||||
result['close_detail'] = str(error)
|
||||
result['close_exception'] = _exception_details(error)
|
||||
library = None
|
||||
if app is not None and not job.get('_native_add_pending'):
|
||||
try:
|
||||
update_worker_state(job, 'CLOSING')
|
||||
app.Quit()
|
||||
dispatch_native(job, lambda: app.Quit(), phase='CLOSING')
|
||||
except Exception as error:
|
||||
result['quit_detail'] = str(error)
|
||||
result['quit_exception'] = _exception_details(error)
|
||||
@@ -1266,12 +1263,11 @@ def management_worker_main(request_path):
|
||||
_write_json(root/'command.json', command)
|
||||
with (root/'native-output.txt').open('wb') as output:
|
||||
_require_management_continuation(job, root)
|
||||
from .session_record import update_worker_state
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
from .session_record import dispatch_native, update_worker_state
|
||||
result['safe_to_continue'] = False
|
||||
try:
|
||||
process = subprocess.Popen(command, stdout=output, stderr=subprocess.STDOUT,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
process = dispatch_native(job, lambda: subprocess.Popen(command, stdout=output,
|
||||
stderr=subprocess.STDOUT, creationflags=subprocess.CREATE_NO_WINDOW), asynchronous=True)
|
||||
except (FileNotFoundError, PermissionError):
|
||||
result['safe_to_continue'] = True
|
||||
raise
|
||||
@@ -1292,6 +1288,7 @@ def management_worker_main(request_path):
|
||||
except subprocess.TimeoutExpired:
|
||||
continue
|
||||
result['wait_exceeded'] = True
|
||||
update_worker_state(job, 'POSTCALL')
|
||||
result.update(safe_to_continue=True, exit_code=code)
|
||||
text = (root/'native-output.txt').read_bytes().decode('mbcs', errors='replace')
|
||||
result.update(success=removal_output_ok(code, text, job['name'], job['partition']),
|
||||
|
||||
Reference in new issue
Block a user