30
30
31
31
from cylc .flow import LOG , __version__
32
32
from cylc .flow .exceptions import (
33
- ContactFileExists ,
34
33
CylcError ,
35
34
ServiceFileError ,
35
+ WorkflowStopped ,
36
36
)
37
+ from cylc .flow .scripts .ping import run as cylc_ping
37
38
import cylc .flow .flags
38
39
from cylc .flow .id import upgrade_legacy_ids
39
40
from cylc .flow .host_select import select_workflow_host
60
61
from cylc .flow .workflow_db_mgr import WorkflowDatabaseManager
61
62
from cylc .flow .workflow_files import (
62
63
SUITERC_DEPR_MSG ,
63
- detect_old_contact_file ,
64
64
get_workflow_srv_dir ,
65
65
)
66
66
from cylc .flow .terminal import (
@@ -474,13 +474,29 @@ async def _scheduler_cli_3(
474
474
async def _resume (workflow_id , options ):
475
475
"""Resume the workflow if it is already running."""
476
476
try :
477
- detect_old_contact_file (workflow_id )
478
- except ContactFileExists as exc :
479
- print (f"Resuming already-running workflow\n \n { exc } " )
480
477
pclient = WorkflowRuntimeClient (
481
478
workflow_id ,
482
479
timeout = options .comms_timeout ,
483
480
)
481
+ except WorkflowStopped :
482
+ # Not running - don't resume.
483
+ return
484
+
485
+ # Is it running? If yes, send resume command.
486
+ try :
487
+ await cylc_ping (options , workflow_id , pclient )
488
+ except WorkflowStopped :
489
+ # Not running, restart instead of resume.
490
+ # (Orphaned contact file will be removed by cylc_ping client logic).
491
+ return
492
+ except CylcError as exc :
493
+ # PID check failed - abort.
494
+ LOG .error (exc )
495
+ LOG .critical ('Cannot tell if the workflow is running' )
496
+ sys .exit (1 )
497
+ else :
498
+ # It's running: resume it and exit.
499
+ print ("Resuming already-running workflow" )
484
500
mutation_kwargs = {
485
501
'request_string' : RESUME_MUTATION ,
486
502
'variables' : {
@@ -489,13 +505,6 @@ async def _resume(workflow_id, options):
489
505
}
490
506
await pclient .async_request ('graphql' , mutation_kwargs )
491
507
sys .exit (0 )
492
- except CylcError as exc :
493
- LOG .error (exc )
494
- LOG .critical (
495
- 'Cannot tell if the workflow is running'
496
- '\n Note, Cylc 8 cannot restart Cylc 7 workflows.'
497
- )
498
- sys .exit (1 )
499
508
500
509
501
510
def _version_check (
0 commit comments