Introduction

FME Server authors often want some action to happen after a workspace finishes successfully and perhaps another action to happen if the workspace fails. For example an author may want a second workspace to run if the first one is successful or to be sent an email if the initial workspace fails.

In FME Server 2012 the Notification Service allows users to create Topics. When a Topic is notified, Subscriptions to that topic are triggered. Subscriptions can be of two types (not including logging):
1. A Push subsciption which can perform an http POST to any web service (including a post to FME Server to run a workspace)
2. An Email subsciption which will send an email

For workspace to notify a Topic and trigger either event it must post a notification to FME Server's REST service. Although the FMEServerNotifier transformer can be used  to notify a Topic on FME Server there is a limitation with this approach. The problem with using the FMEServerNotifier is that when a feature reaches this transformer and triggers it we do not yet know that the workspace completed and whether it was successfull or not.

The steps and sample below explain how to use a Shut Down Python Script to notify FME Server on success or failure after the workspace has finished.
Run it Live
Note: The live demo running on FMEServer.com asks you to test success or failure. Rather than send an email on failure, in either case a second workspcae will run and tweet whether the first one succeed or not so you can see the results. The twitter account used is MrFMEWorkbench



Steps

1. Create the Topics
Start the FME Server Web Admin UI (Start > Programs > FME Server > Web Admin Interface) and login. Go to the Notifications tab and click the Topics tab within it.  Create two new Topics: MySuccessTopic and MyFailureTopic.



creating Topics in  FME Server Web Admin UI

2. Publish the Success Workspace
Open FME Workbench and open the attached workspace Number2.fmw. This workspace willl be run only if the first one is successful. It is very simple for testing but it can contain any workflow you would like done after the first workspace is run. Publish this workspace to FME Server in any repository and register the workspace with the JobSubmitter serivce and with the Subscription service. Click the Edit button beside the Subscription service and in the dialog choose MySuccessTopic from the Assigned Topics. Leave the rest of the dialog with the defaults and click OK to finish publishing the workspace.


Publish to Job Sumbitter and Notification Service - select Topic

3. Set-Up the Subscriptions
a) Go back to the Web Admin UI - Notification tab and click on the Subscriptions tab within it. You should see that a new Push subsciption has been created for this topic when you published the Number2.fmw workspace. If you click Configure on this subsciption you will see that the target url is the url needed to run your Number2.fmw workspace. Now if FME Server receives a notificaiton on the topic MySuccessTopic your workspace Number2.fmw will be run.
b) We can set up an email subscription for the MyFailureTopic in the same tab of the WebAdmin UI. Under Subscriptions click New and choose the type Email. Enter the email settings, if you have a gmail account you can use for testing the parameters to use are shown below - otherwise you will need to know your own email settings. At the bottom of the dialog be sure to add the topic MyFailureTopic to the Assigned Topics list.
Settings for Gmail accounts:

  • SMTP Server: smtp.gmail.com
  • SMTP Server Port: 465
  • SMTP Account: <full email address>
  • SMPT Password: <password>
  • Email To: <email address for notification of failure>
  • Email from: <same full email address as account>
  • Email Subject: Workspace Failed

set-up of email subscription


4. Run the Primary Workspace
Open the attached workspace NotifyFMEServer.fmw. Again the workspace is very simple so it can be used for testing, but this workspace can contain any workflow to be done first, before notifying FME Server to run the second workspace. The workspace contains a Shutdown Python Script which notifies FME Server topics based on success and failure.  You can examine the script in the Navigation Panel by going to Workspace Parameters > Advanced > Shut Down Python Script. The script can be copied into anyother workspace as long as you create and set the published parameters listed below.

Below are the parameters required by the script. The parametes are published in sample workspace but can be converted to private parameters if you prefer. Use File - Prompt and Run to start the workspace and set the parameters.
  • SuccessTopic: MySuccessTopic
  • FailTopic: MyFailTopic
  • FME Server Host: <url to root of your FME Server Host> e.g. http://yane:8080
  • UserName and Password
  • or you can use a Token: <RestSecurityToken>*
  • Succeed or Fail:  If you choose fail the workspace will fail and simulate a real failure
*Get a REST Security token by opening your FME Server REST User Interface, Start > Programs > FME Server > REST Interface.  Here you can log in to create and copy security Token.

Once you have set the parameters go ahead and run the workspace in FME Desktop. The log will show whether the workspace successfully notified FME Server of it's success or failure.


parameter for primary workspace


5. Viewing the Results
After running the workspace go back to the Web Admin UI and click on the Jobs tab to view the Job History. You should see that workspace Number2.fmw was just run because it subscribed to the MySuccessTopic which was notified by the script in the primary workspace.

Viewing the Job History on FME Server

Now enable the Terminator tranformer to the workspace NotifyFMEServer.fmw and run it again in FME Desktop. This time the workspace fails and your email should have been sent because there was an email subscription to the MyFailureTopic . Check your email to confirm. 


6. Publish the Primary Workspace
Publish the workspace NotifyFMEServer.fmw to FME Server and register it with the Job Submitter Service. This workspace could be scheduled or run by any service. No matter how it is run on FME Desktop or on FME Server, the shutdown python script will run and attempt to notify FME Server.

Run the workspace NotifyFMEServer.fmw using the FME Server Web User Interface. Again in the Job History you should see that Number2.fmw has been run.