Skip to main content
Hello:

 

 

I have two FME programs:

 

 

1) Loads data in one spatial table

 

2) Loads data in another spatial table

 

 

I would like to :

 

 

- Keep these scripts independent, so script 1 can run on demand and to its thing, and

 

- Script 2) can call script 1), for extra processing.

 

 

My problem is, how do I invoke Script 1) from Script 2)? 

 

They both do different data processing, but it will be great if one can call the other.

 

 

I am struglling with how to invoke Script 1, because there is no way "to trigger" its processing. I would like that, once Script 2 is done, it automatically triggers Script 1.

 

 

Is this possible to do? I have been trying to do this with WorkspaceRunner, but I don`t get it to "run"

 

 

Thanks again.

 

 

Richard.

 

 

 

With WorkspaceRunner you can set it to Wait for Job to Complete for 'Script2', then use a second WorkspaceRunner to run 'Script1' .

 

I assume you mean a Workbench when you say scripts.
Nevertheless, I think using a third workspace with 2 WorkspaceRunners is the best way.

 

You can use a Creator transformer as "input" (i.e. the trigger to run Script 2) of the third workspace.

 

 

Creator: create 1 feature as trigger

 

--> WorkspaceRunner: run Script 2 * Wait for Job to Complete = yes

 

--> WorkspaceRunner: run Script 1

 

 
Hi Takashi: I agree with you, but unfortunately, I need to adhere to some standards and requirements to resolve this problem and unfortunately using three scripts is out of the question. I truly appreciate your help though. There must be a way to do this. I continue investigating 🙂 Best regards Richard
Running Script 1 by using command-line in the shutdown script of Script 2 may be possible. But I think it's not a general way, I don't recommend it if there are other usual ways.
Hi Richard,

 

 

you can do this by writing a small Python shutdown script, using the FMEWorkspaceRunner API. This small example, used from worspace1, executes workspace2 when workspace1 completes:

 

 

------

 

import fmeobjects current_workspace_dir = FME_MacroValuesa"FME_MF_DIR_UNIX_MASTER"] wsr = fmeobjects.FMEWorkspaceRunner() wsr.runWithParameters(current_workspace_dir+"/workspace2.fmw",     {"SourceDataset_SHAPE": FME_MacroValueso"DestDataset_SHAPE"]}) ------

 

 

It also transfers a parameter from workspace1 to workspace2. Tested using FME2012. Let me know if you have questions to the above.

 

 

Hope this helps.

 

 

David
David, nice demo. Anything to think about when porting this to FME Server?
Hi Sig,

 

 

I'd be delighted if somebody had the time to test my solution with FME Server. I have made my demo workspaces available here.

 

 

If you're able to test it, please let me know how it works.

 

 

David
Nice - I'll add that to my inventory Thanks!
To maybe summarise the answers for the original poster:

 

 

1) You can use a WorkspaceRunner in Script2 to call Script1. You just need something to trigger it once. Use a Creator or a Sampler transformer to get a trigger feature.

 

 

2) If you do use a WorkspaceRunner, one issue is that Script2 won't be fully completed - because its writers won't have finished - when Script1 is triggered. If this is a problem (and it might not be for you) the only solution (using WorkspaceRunners) is to use a third (control) workspace to run Script2 then Script1, waiting for Script2 to complete.

 

 

3) A shutdown script can be used instead. It won't be triggered until Script2 is complete, which solves the WorkspaceRunner issue in #2. The one thing I would add to David's script is a check for the status of Script2. In Tcl it would be:  if {$FME_Status == "1"} ..... because you probably won't want to run Script1 if Script2 has failed.

 

 

Two other methods I'll mention:

 

 

4) If Script2 writes to a database, set a trigger in the database to run Script1

 

 

5) If you have FME Server, then you can set up a Notification/Alert to run Script1 in response to Script2.

 

 

Hope this is useful. Thanks to everyone for the great suggestions.

 

 

Mark

 

Mark Ireland

 

Product Evangelist, Safe Software Inc.
Mark, very good idea to check for the workspace status in the shutdown script.

 

 

For reference, here is the modified Python shutdown script with your suggestion included:

 

 

-----

 

import fmeobjects   if FME_Status == 1:     current_workspace_dir = FME_MacroValuesr"FME_MF_DIR_UNIX_MASTER"]     wsr = fmeobjects.FMEWorkspaceRunner()     wsr.runWithParameters(current_workspace_dir+"/workspace2.fmw",         {"SourceDataset_SHAPE": FME_MacroValues "DestDataset_SHAPE"]}) -----

 

 

Just watch those indents and newlines in the script above, this forum system isn't too kind with code.

 

 

David
Hello again:

 

 

Thanks for all the advice, it is much appreciated. I have finally got everyone here to decide that we will use only two scripts and I have a portion of code in Python that we need to incorporate to achieve what we need.

 

 

Is there any "friendly" way to incorporate Python code in the FME Workbench? Or should I edit the FMW file in a text editor?

 

 

Thank you!

 

 

Richard

Reply