Score:0

How to write a batch job query that has wait times, dependencies and conditional execution?

kr flag

I'm trying to write a batch job that executes via task scheduler. The objective is to run these exe jobs sequentially. However, some of these jobs have dependencies on others. for eg.

  1. job1.exe (no dependencies. exe for an API call)
  2. job2.exe (no dependencies. exe for an API call)
  3. job3.exe (python file in exe, requires job1 to run successfully, waiting 3 mins before executing)
  4. job4.exe (python file in exe, requires both job2 and job1 to run successfully waiting 3 mins before executing)

Aim : to run job1 and job2 in parallel job3 and job4 whenever possible currently it's set up like this:

START /min "" "%~dp0\ job1.exe
IF %ErrorLevel% EQU 0 (
    TIMEOUT /t 180
    START /min "" "%~dp0\job3.exe) 
)ELSE (
    ECHO job3 did not run because job1 failed
TIMEOUT /t 180

START /min "" "%~dp0\ job2.exe
IF %ErrorLevel% EQU 0 (
    START /min "" "%~dp0\job4.exe) 
)ELSE (
    ECHO job4 did not run because job2 failed
TIMEOUT /t 180 

Currently, the jobs don't work.

SamErde avatar
gg flag
Are the jobs failing when you run the batch file manually, or is the scheduled task failing to run? What error[s] are you getting? Do any of the processes require elevation, interaction, or start a windowed application?
JosefZ avatar
th flag
**1st** there are syntax errors (missing trailing double quotes). **2nd** Even if you fix those, e.g. `START /min "" "%~dp0job1.exe"` then `job1` should run in parallel (asynchronously). **3rd** You should initially [set `ErrorLevel` to 0](https://superuser.com/a/649329/376602) (read more about ErrorLevel at https://ss64.com/nt/start.html).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.