File conditions in subdirectories

Paul Watson (101 posts)
April 16, 2018 01:25 PM
Accepted Answer

We have had good success using a single trigger file under a subdirectory structure. Only "\Vendors\trigger.txt" is specified. When a "trigger.txt" file is found in any of the "Files" subdirectories, the job is started.

\Vendors\IBM\Files

\Vendors\HP\Files

\Vendors\Dell\Files

The problem is that we need to cause any new trigger file job to wait until the previous job is completed for that vendor. It is ok to run an HP and Dell job concurrently, but not two (2) HP jobs concurrently.

When the job starts, I write a "running.now" file into the vendor directory (IBM, HP, Dell). I would like to use that as a Condition. The new job must wait until the "running.now" file is deleted.I have tried creating a Condition based on "%FileTrigger.FileName%\..\..\running.now", but I do not think the "FileTrigger.Filename" is resolved when the conditions are evaluated.

This makes me think that all Triggers should be evaluated first, before any Condition. But, I think that is not how it works.

Do you have any suggestion to accomplish this?

Bill Staff (604 posts)
April 16, 2018 03:02 PM
Accepted Answer

When the trigger finds a file, it triggers the job. At that point your File Condition (I assume that's what you're using) will kick in and wait till the file doesn't exist.

The problem is that the File Condition doesn't resolve the relative path you have given it, so that's not producing a valid file name for it to look for. You can fix this by creating a new function to resolve the path for you.

Go the Scripts/Script Libraries node and edit the InlineFunctions library. Assuming its language is set to VB.NET, add this function:

Public Function ResolvePath(source As String,relativePath As String)
     Return New System.IO.DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(source),relativePath)).FullName
End Function

if it's C#, use this:

public static string ResolvePath(string source, string relativePath)
{
     return new System.IO.DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(source),relativePath)).FullName;
}

This function takes a filename (source), gets the directory name, then appends relativePath to it and resolves that to the full name.

Now set your File Condition to look at this:

%=ResolvePath("%FileTrigger.FileName%","..\running.now")%

Given a trigger file name of "C:\Vendors\IBM\Files\somefile.txt", that's going to produce "C:\Vendors\IBM\running.now".

You may have another problem, though: if more than one "IBM" job gets triggered while an "IBM" job is running, then they will all be waiting for the condition to be met, and when it is they will all be released at once--none of them will have a chance to create the lock file before the others all start. I don't have a good solution for that problem offhand, other than to have a separate job for each vendor.

 

Replies are disabled for this topic.