Adding a simple txt file to a job folder.

Post Reply
wolle
Newbie
Posts: 11
Joined: Thu Dec 09, 2010 9:37 am

Adding a simple txt file to a job folder.

Post by wolle »

I bet there's a simple solution to this:



I need to add a text file to the jobfolders that pass through my flow. It's the same file every time and the job folders must not change name or metadata (from xml-file).



I've already made a flow with job dismantlers, job injectors and assemble job elements, with a hold job element at the beginning to keep the jobs apart. It's a big, dumb flow that ends up with a bunch of anonymous folders called Job011, Job012 etc.



So what is the "Put file into job folder"-element really called?



Kind regards

Thomas
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Adding a simple txt file to a job folder.

Post by dkelly »

You could create a simple script element that calls sendToSingle( path ). If you don't want to delete the source file, then you will need to copy it to a temporary location first.
wolle
Newbie
Posts: 11
Joined: Thu Dec 09, 2010 9:37 am

Adding a simple txt file to a job folder.

Post by wolle »

Hmm, how will that merge the textfile and the job folder into one job?



It it something like:



createPathWithName(createFolder: "temporary") and then somehow send the arrived job and the textfile to this folder.



And THEN sendToSingle() where you send the folder in the temporary path to the one outgoing connection?



Will it keep metadata and jobname like that?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Adding a simple txt file to a job folder.

Post by dkelly »



// InjectFile

// Developed by Dwight Kelly <dkelly@apago.com>

// Copyright 2011 - All rights reserved



function jobArrived( s : Switch, job : Job )

{

var String theFileToInject = s.getPropertyValue( "file" );

if ( theFileToInject.length ) {

var injectedFile = new File(theFileToInject);

var String tmpFile = job.createPathWithName( injectedFile.name );

s.copy( theFileToInject, tmpFile );

job.sendToSingle( tmpFile );

}

job.sendToSingle( job.getPath() );

}

wolle
Newbie
Posts: 11
Joined: Thu Dec 09, 2010 9:37 am

Adding a simple txt file to a job folder.

Post by wolle »

Just so you know it, Dwight: I admire you immensely! :-)



Out of curiosity:



When you make the temporary path and copy theFileToInject to it, then you first send the temporary path to the out connection, and then finally the job itself.

Will the two sendToSingle-statements send to the same job? Won't they end next to each other as a folder and a file - that is, as two separate jobs?



(my head hurts - I'm gonna try it out instead of trying to figure it out.)



Kind regards

Thomas
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Adding a simple txt file to a job folder.

Post by dkelly »

>Will the two sendToSingle-statements send to the same job? Won't they end next to each other as a folder and a file - that is, as two separate jobs?



Since both sendToSingle() calls refer to the same job variable, they are associated with a single job.



Let me know if you need a functional flow.
wolle
Newbie
Posts: 11
Joined: Thu Dec 09, 2010 9:37 am

Adding a simple txt file to a job folder.

Post by wolle »

I tried your script, but couldn't get it to work (it just leaves the txt-file next to the job-folder, so the jobs aren't merged).



I then tried a pretty complex flow, that spaces jobs apart, injects the txt-file, dismantles the job so all the individual fles are mixed with the one txt-file and after a few minutes they are all assembled into one job that's named after the original job-folder. Phew! it's slow, data-heavy and fails one in 20 times for no good reason!



If I can just get a script to do what we talked about, it could replace some 20 script-elements and make the script work fast and without faults.



Any ideas?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Adding a simple txt file to a job folder.

Post by dkelly »

I just uploaded the flow, Inject static file, to Crossroads that does what I think you needed.



Dwight Kelly

Apago, Inc.

dkelly@apago.com
wolle
Newbie
Posts: 11
Joined: Thu Dec 09, 2010 9:37 am

Adding a simple txt file to a job folder.

Post by wolle »

It works like a charm. Also I've learned some cool tricks from your setup, so thank you again!



But it's not really that easy to do in a script, huh?
Post Reply