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 :-)


Warm Regards,
Nikhil Thampi
Please appreciate our members by giving Kudos for spending their time for your query. If your query is answered, please mark the topic as resolved :-)

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.