How to Capture Job Exit Code?
If you create a FUNCTION and query the sysjobhistory table in MSDB you can get a simple response on the most recent job execution.

Create the function:

CREATE FUNCTION [dbo].[fnGetLatestAgentJobExitCode]
(
    @JobName VARCHAR(100)
)
RETURNS VARCHAR(25)
AS
BEGIN
    RETURN(
        SELECT TOP (1)
            CASE jh.run_status
                WHEN 0 THEN 'Failed'
                WHEN 1 THEN 'Succeeded'
                WHEN 2 THEN 'Retry'
                WHEN 3 THEN 'Canceled'
                WHEN 4 THEN 'In Progress'
            END AS [Status]
        FROM [msdb].[dbo].[sysjobactivity] ja
        INNER JOIN [msdb].[dbo].[sysjobs] j ON j.job_id = ja.job_id
        INNER JOIN [msdb].[dbo].[sysjobhistory] jh ON jh.job_id = j.job_id AND jh.instance_id = ja.job_history_id
        WHERE j.[name] = @JobName
        ORDER BY ja.start_execution_date DESC)
END


Then query it like so:

SELECT [dbo].[fnGetLatestAgentJobExitCode]('myJob')


This will give one of the following results:

Failed
Succeeded
Retry
Cancelled
In Progress


Or will return no result if there is no job history. To use this in your specific use case would be simple:

WHILE (SELECT [dbo].[fnGetLatestAgentJobExitCode]('myJob') = 'In Progress')
BEGIN
    WAITFOR DELAY '00:00:05.000'

    IF (SELECT [dbo].[fnGetLatestAgentJobExitCode]('myJob') = 'Failed')
    BEGIN
        BREAK
    END
END

IF (SELECT [dbo].[fnGetLatestAgentJobExitCode]('myJob') = 'Succeeded')
BEGIN
    EXEC msdb.dbo.sp_start_job 'myJob'
END