Get exit code of a job run from an external java application

Six Stars

Get exit code of a job run from an external java application

Hello,

 

I am developping a little java application that can run a job depending on some conditions.

All I want is to know inside my java code if the job run successfully or not. 

Here is my code :

 

        job_launcher talendJob = new job_launcher();
        String [] context = new String[] {"--context_param row_id="+customMessage.toString()};
        String[][] code = talendJob.runJob(context);

        for(String[] s : code){
            for(String s2 : s){
                log.info(s2);
            }
        }

The problem is that the returning code is always 0, even if my job throws a null pointer exception or something else.

 

So how can I proceed to determine if my job failed ?

 

Thanks,

Guillaume

 

 

Employee

Re: Get exit code of a job run from an external java application

Hi,

 

    Since you are using the main class, it is giving the exit condition as 0. 

 

     Could you please try below code snippet?

 

String[] args = {};

local_project.helloworld_0_1.helloworld obj1 = new local_project.helloworld_0_1.helloworld();

int exitCode = obj1.runJobInTOS(args);

if (exitCode != 0)

	      {
	
	throw new NullPointerException("Demo exception - Child job failed !!!! "); 
	}

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now