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

 

 

Highlighted
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 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog