Automic Workload Automation

Expand all | Collapse all

Execute a job if any one of the prior jobs completed

Matthias Schelp

Matthias SchelpJun 05, 2018 03:44 AM

  • 1.  Execute a job if any one of the prior jobs completed

    Posted Jun 04, 2018 09:04 PM

    Hi All, I have JOB F1 and JOB F2 and both are file watchers(EVENTS) looking for file1 and file2. I need to execute a job  J99 if any one of the jobs F1 or F2 is success. Could you please help me on how to implement this ?  If any of the file exists, I need to execute third job. 



  • 2.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 03:27 AM

    Hello,

     

    maybe you can use the ACTIVATE_UC_OBJECT function in each file events. So when ever one of the file checks are successfull  - run the job started by the script (!script tab)

     

    Thomas



  • 3.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 02:55 PM

    This would work, but also might result in running the successor object twice if both F1 and F2 were to execute.  That might be ok though?



  • 4.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 03:44 AM

    Hi,

     

    this should do the trick ...

     

     

    Regards, Matthias



  • 5.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 01:40 PM

    Thanks for reply. But the third job is still waiting for the first two jobs to finish. My requirement is if any one of the first two jobs finishes, I want to start the third job and ignore the other job in first two jobs and finish JOBP. Thank you for looking into this. 



  • 6.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 02:48 PM

    Too bad the workflow idea didn't work.  But that makes sense that it won't check the end-of-job condition on the two jobs until they actually finish.

     

    So how about an old fashioned switch variable?  Set up a new static variable called MY.PROCESS.STATE and throw a row into it with a key of "PROCESSHASRUN" and a value1 of "NO".   F1 and F2 are then both coded to set this value to "YES" at end of job.  Put the successor job inside of a workflow with a precondition rule on the jobs task properties that says wait until {MY.PROCESS.STATE,PROCESSHASRUN,1} = "YES".   Setting the variable back to "NO" can be tricky though since either F1 or F2 might run after the successor job has run, which would throw it back to "YES".  So maybe run a script at midnight to set it to "NO" or something like that.

     

    Kind of clunky, but works.  I'm still trying to think of an elegant solution...



  • 7.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 07, 2018 03:06 AM

    Peter WIRFS schrieb:

     

    Too bad the workflow idea didn't work.  But that makes sense that it won't check the end-of-job condition on the two jobs until they actually finish.

     

    Oh year sorry NagsK , I had that feeling I kind of missed something ...



  • 8.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 03:26 PM

    Hi

    what about the ACTIVATE_UC_OBJECT - solution?

    Its the most simple one...

     

    cheers, Wolfgang



  • 9.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 05, 2018 06:31 PM

    For Now I followed the below approach using a variable. But please let me know if you have better idea....

     

    1) In Events job "Process"

    :PSET &CHKSTS# = "NO"

     

    2) In Events job "!Process"

    :PSET &CHKSTS# = "YES"

     

    3) In Pre-Process of my next JOBS 

     

    : IF &CHKSTS# = "YES"
                : PRINT "CHECK STATUS = &CHKSTS#"  --> This just prints the status and executes the JOBS
    : ELSE
                : EXIT 0     --> This will simply exits the JOBS. I don't want to fail the job so I gave 0 as return code
    : ENDIF



  • 10.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 07, 2018 03:12 AM

    Hello,

     

    did you consider to use the Filelist VARA object. This also could help ypu with that request.

     

    Having Filelist VARA Objects linked to the OS systems and folders you want to monitor. Having a time event (or other object type) checking the VARA objects and react if the result you are looking for are given

     

    Thomas



  • 11.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 07, 2018 09:31 AM

    Okay second try,

     

    how about preconditions ...

     

     

    Don't forget to kill the job after x iterations (also via preconditions or via MRT).



  • 12.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 07, 2018 12:54 PM

    I haven't given up on the workflow idea.  What if the workflow had two "threads" like so, with F99 as two separate tasks?

     

    START

       F1 => F99 => END

       F2 => F99 => END

     

    And if you only want to allow F99 to run once, it could manipulate a workflow variable and check it in a precondition.



  • 13.  Re: Execute a job if any one of the prior jobs completed
    Best Answer

    Posted Jun 07, 2018 03:53 PM

    Hi Guys

    Do you wanna hear the answer of a certified smartass?

     

    Anyway if you say Yes or No I'll explain (as it took me half an hour thinking and testing)

     

    Yes it will work in a workflow - but only with a stupid trick.

     

    Requirement is: IF JOB F1 OR JOB F2 found a file. Common Workflow Logic is - one job follows the other that means, if you have 2 predecessors and a successor the successor will start running, if BOTH of them have an(y) end status no matter which one in range 1800....1900.

     

    So the common Workflow logic won't work in this case !!

     

    Many years ago when I started playing with this UC4 Version 8  I learned, if you do not connect Objects in a workflow with lines they will get executed at workflow start.

    So my Idea was using a precondition in the successor job.

     

    So at workflow start both EVNTs start as well.

     

    I put a dummyfile "file2.txt" to the check directory and have to wait until Precondition re-evaluation check is done (3 Minutes)

     

    both EVNTs have a max_runtime setting of 1 minute

    So the successor job starts running

     

    I tested with file1.txt and another run with file2.txt, both situations were working.

     

    Thats it, easy cheesy, if you know how :-)

     

    If you want the exports pls let me know.

     

    cheers, Wolfgang



  • 14.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 08, 2018 06:32 PM

     wow!!  THANKS ALL and Wolfgang. Final question.    I have not yet tested but quick question. what is happening to JOBP if only one file is exists or coming in ? is it ending ? OR still waiting for second file event ?

    If it ends ENDED_OK, my problem is solved. So I can schedule JOBP for every 2 mins. 

    I never thought OUT OF BOX . always tried with links. Thanks man. 



  • 15.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 08, 2018 06:34 PM

    If you get a chance, I posted another question. Could you please look at it ? 

    Can we give file patterns in Event-File Object ? 



  • 16.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 11, 2018 06:12 PM

    Hi Wolfgang, Got small issue here ....   Here are my observations after testing... 

     

    below is my JOBP

     

     

    first two jobs looks for file1.txt and file2.txt respectively and third job JOBS touches file called process.txt. 

    As you see above, I have given the alias names  ALIAS_FILE1(original event name : EVNT.NAG.TEST) and ALIAS_FILE2(Original event name : EVNT.NAG.TEST2) 

    And in the precondition of the JOBS.... below are the conditions .

     

    ***I am not using ANY_OK since the job is kicking off even the file watcher completed due to max time out of 1 min.

    OK .... As per your suggestion, in TASK PROPERTIES of the both File watchers  I have set max run time to 1 min ELSE cancel/quit as shown below. 

     

    Now the problem is as soon as I kick of my JOBP, following two messages are getting displayed in message window.

     

     

    So does it means, it is already cancelled ? or still running in back ground ? 

    what I found is these two tasks are still running in background even after 1 min and generating the following logs in report window. 

    Now I created file1.txt and waited for the first file watcher to finish and then JOBS also got succeeded and JOBP also got completed and closed the monitor.

     

    But in activities window, I can still see the second file watcher running alone (outside of JOBP)

    I ran the JOBP again and I touched file2.txt this time and ALIAS_FILE1 was appearing in activities window this time.

     

    Can I avoid of running these file watchers after JOBP is done ?  Also see the properties of events below

     

     

    Next I ran the JOBP in recurrence mode for every 1 min. see the properties below.  But it is never getting completed even there is file2.txt.

     

     

    see the activities window below...

     



  • 17.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 12, 2018 02:24 AM

    Hi

     

    you defined one second as MRT - thats a bit too short :-)

     

    Minimum one minute, better 2.

     

    cheers, Wolfgang



  • 18.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 12, 2018 07:42 PM

    Still that issue is there. I am not sure where I am doing the wrong. I tried multiple times, but only time time I have seen the Event file watchers ended with status ENDED_TIMEOUT. All other times including latest run, the F1 and F2 are running even after they timed out. see the settings below.

    Below is my JOBP. first two file watchers with the above mentioned properties (from previous post). 

     

     

     

    I have started this job in recurring mode for every 2 mins. I can see that the file watchers are ending with ENDED_TIMEOUT. But the third job is keep on running. I created the file file1.txt, of course nothing happens because file watchers are already dead. But JOBS is still running.  Then for JOBS, I kept 3 mins as Max Run Time (MRT). But still that job is not ending. Any clue ? 



  • 19.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 13, 2018 03:38 AM

    Hi

     

    Event file watchers ended with status ENDED_TIMEOUT.

    => I would set the MRT for the whole workflow, so if the file watchers do not find the files it should be cancelled including all objects in it.

     

    Why Your EVNTs run outside the workflow I have no Idea, con only guess it was started seperately by mistake...

     

    cheers, Wolfgang



  • 20.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 13, 2018 03:39 AM

    Hi again

     

    the -outsde running EVNTs do have a parents - see screenshot - I sppose thsi is a workflow....

     

    cheers, Wolfgang



  • 21.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 14, 2018 11:46 PM
      |   view attached

    I haven't really been following this thread, and I didn't want to steal Wolfgang's thunder.  But I couldn't help myself and I came up with a different approach.  This approach uses a SYNC object on all three jobs to apply a rule that only 2 of the jobs can run at a time, and then I added a precondition rule onto the last step that forces it to have a one minute delayed start.  I'm attaching a result screen and an export of my test objects.  All three jobs have a waittime variable built into them so you can manipulate which one will finish first for different test scenarios.

     

    Attachment(s)

    zip
    uc4_export.xml.zip   2 KB 1 version


  • 22.  Re: Execute a job if any one of the prior jobs completed

    Posted Jun 20, 2018 02:40 AM

    Absolutely no problem - the technical solution counts :-)

     

    cheers, Wolfgang

     

    PS: cought me, Im not in syncs :-P