Page 1 of 1

Syntax for Multiple job.createchild()

Posted: Tue Mar 04, 2025 11:34 am
by Tenzo
Hey all,

So, I am used to creating one child job and using send to data, though now I have encountered something I am not sure how to accomplish.
I have a job "Input Job" but then I need to create two child jobs from that one each with their own Private Data.
What would the syntax be for this? Just not sure how two create Multiple new childjobs then send thoses jobs to send to data.
Any help on this would be appreciated!

Code: Select all

	Input job = await job.get(AccessLevel.ReadWrite);
	<----Customize Input job With Imagemagick---->
	
	<----Customize Input job With Imagemagick---->
	let New_Job_1 = await job.createChild(Input job);
	await New_Job_1.setPrivateData(Set_Private_Data(PD1));
	await New_Job_1.sendToData(Connection.Level.Success)
	
	<----Customize Input job With Imagemagick---->
	let New_Job_2 = await job.createChild(Input job);
	await New_Job_2.setPrivateData(Set_Private_Data(PD2));
	await New_Job_2.sendToData(Connection.Level.Success)

	await job.sendToNull();

Re: Syntax for Multiple job.createchild()

Posted: Tue Mar 04, 2025 1:16 pm
by laurentd
exactly

Re: Syntax for Multiple job.createchild()

Posted: Tue Mar 04, 2025 2:16 pm
by Tenzo
laurentd wrote: Tue Mar 04, 2025 1:16 pmexactly

Okay thanks!
That indeed worked. I had been running into issues with this.

I had the right syntax in the script, but I had also forgotten to remove and extra send to null after the first one.
So, I was getting the error "Have you called any sendTo method already?" .

Everything makes sense now.
Thanks for the response laurentd

Re: Syntax for Multiple job.createchild()

Posted: Wed Mar 12, 2025 12:27 am
by Tenzo
laurentd wrote: Tue Mar 04, 2025 1:16 pmexactly
Back again,
While this was the solution to my original issue, I am kind stuck on a similar issue now.

Is there by chance a way to pass the job instance to another function?
I'm using async Job arrived for one input job, but I am making lots of jobs from that one file.

It works if the child job is created in the async Job arrived, but all of the child jobs don't arrive in the output folder until the async function is done, hence wanting to use another function to create and output jobs while the async function works on the next iteration. Any ideas on how this could be done?

Code: Select all

async function jobArrived(s: Switch, flowElement: FlowElement, job: Job): Promise<any> {

	Input job = await job.get(AccessLevel.ReadWrite);
	<----Customize, Calculate, etc.---->
	
	arrayOfJobs foreach(
	Create_Job(Input job, Other Params);
	)
}

Create_Job(job, Other Params){

let New_Job = job.createChild(job);
New_Job.setPriority(Job_Priority);
New_Job.sendToData(Connection.Level.Success);

}


Re: Syntax for Multiple job.createchild()

Posted: Wed Mar 12, 2025 5:36 pm
by tdeschampsBluewest
Hi,
In order to create a child job, you need to give a path to this new job as a string.
You are also missing an async/await on your create_Job function.


Note that when you create a new child job, it must NOT be the same path as the original job (as it will be moved when the .sendTo... is executed.

If you want to make multiple copy of the same job, you'll have to duplicate them first (With FS + tmp for example)

Code: Select all

async function jobArrived(s: Switch, flowElement: FlowElement, job: Job): Promise<any> {
    const paths: string[] = [];
    //Some code to populate Paths

    for (let path of paths) {
        await create_Job(job, path, "other", "params");
    }
    await job.senbdToNull();
}

async function create_Job(job: Job, path: string, Other: any, Params: any) {
    let New_Job = await job.createChild(path);
    await New_Job.sendToData(Connection.Level.Success);
}


Re: Syntax for Multiple job.createchild()

Posted: Wed Mar 12, 2025 8:45 pm
by Tenzo
tdeschampsBluewest wrote: Wed Mar 12, 2025 5:36 pm Hi,
In order to create a child job, you need to give a path to this new job as a string.
You are also missing an async/await on your create_Job function.


Note that when you create a new child job, it must NOT be the same path as the original job (as it will be moved when the .sendTo... is executed.
I thought I have it right, but for some reason the jobs only show up in the Success Folder only AFTER the entire loop in jobArrived is done. Then they all show up at once.

Code: Select all

async function jobArrived(s: Switch, flowElement: FlowElement, job: Job): Promise<any> {
	await Create_Job( job, Generated_Image, Private_Data, Selected_Date, Order )
}	
async function Create_Job(job:Job, Generated_Image:string, Private_Data:any, Selected_Date:Date, Order: Order_Details) {
    let New_Job = await job.createChild(Generated_Image);
    New_Job.setPrivateData(Private_Data);
    await New_Job.log(LogLevel.Info, `Processing: ${[Order_Index+1]} / ${Batch_Data.length} Orders.`);
    await New_Job.sendToData(Connection.Level.Success);
}
The path to the new job seems valid and this iis from the debug console in VSCode.

Code: Select all

[INFO] _createJob: Uploading job files from C:\Temp Folder\Image Creation\2767368.png, config={
  "method": "blahblah",
  "url": "http://blahblah/api/v1/job/0BBC3/child",
  "token": "blahblah",
  "isLocal": true
}