on 07-15-2018 5:47 AM
Hey Experts,
I am trying to read .txt file with the help of below code (Redwood Script definition used to run the below code ) Moreover I have passed the .txt file with the help of Parameter (File).
But I am getting error File input error
I am trying to achieve this with two types of script code. I have attached the script file here (Name of the file : read-the-txt-file.txt)
Here is the code :
Hi Narayan,
To accomplish what you want, try below code.
Replace jdName with the name of your job definition, and Partition p with the name of the partition of the job.
This should set restarts to 1, and On error to restart with 2m delay.
import com.redwood.scheduler.api.model.*;
import com.redwood.scheduler.api.exception.*;
import com.redwood.scheduler.api.model.enumeration.*;
import java.util.Iterator;
{
String jdName = "YourJobDefinitionName";
Partition p = jcsSession.getPartitionByName("GLOBAL");
JobDefinition jd = jcsSession.getJobDefinitionByName(p, jdName);
if (jd != null) {
jd.setRestartCount(1L); // Set Max restarts to 1
// Get the status handler for 'On Error'
FinalStatusHandler handler = jd.getFinalStatusHandlerByStatus(JobStatus.Error);
if (handler == null) {
// Status handler does not exist, create a new one.
handler = jd.createFinalStatusHandler();
}
handler.setAction(FinalStatusAction.Restart);
handler.setStatus(JobStatus.Error);
handler.setRestartDelayAmount(2L);
handler.setRestartDelayUnits(TimeUnit.Minutes);
try {
jcsSession.persist();
} catch ( SchedulerAPIPersistenceException e) {
jcsErr.println(e.toString());
}
jcsOut.println (jd.getName() + ", " + "Created status handler: " + "ON " + handler.getStatus() + ", " +
handler.getAction() + ", " + handler.getRestartDelayAmount() + ", " + handler.getRestartDelayUnits());
} else {
jcsOut.println("Error: Job definition not found : " + jdName );
}
}
Kind regards,
Bas Valentijn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank You Bas !! It works perfectly 🙂
You are well versed in Redwood Scripting, hats off Man !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much !!
Actually with the help of file read I want to update process definitions. I just want to pass the txt file and update the Process status(Maximum starts and On error action).
Are you aware which method should I call to update Process status (Maximum starts and On error action).
If you can share that piece of code which I can help me to build further.
Note: we want to update process status for list of jobs, on error job should restart once and action delay of 2 minutes.
I am beginner to redwood script if you can help me anyway to locate the documents of redwood script which can help me to build further on redwood scripting.
Your help will be much appreciated !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Narayan,
Since you have defined a job definition parameter of type File, I assume you are uploading the physical .txt file to the job on submit.
If you do that, the file will actually be attached to the job as 'upload.dat'
You can use below example code to get access to the uploaded file, and type out it's text contents
import java.io.*;
import com.redwood.scheduler.api.model.*;
{
// Get the attached file
JobFile jobfile = jcsJob.getJobFileByName("upload0.dat");
String filepath = jobfile.getFileName();
String line;
if (jobfile != null) {
jcsOut.println("Full path and filename : " + filepath);
FileInputStream in = new FileInputStream(filepath);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((line = br.readLine()) != null) {
jcsOut.println(line);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.