Skip to main content
Solved

Capture date that a FME Workbench started to run?

  • September 12, 2023
  • 3 replies
  • 169 views

nicholas
Contributor
Forum|alt.badge.img+11

I have a FME workbench that is scheduled to run late in the evening, and it is a lengthy process, so it can sometimes run over midnight.

Is there a way I can capture the date of the day that the workbench started to run and to store that date in a parameter?

I tried DateTimeStamper but it re-captures the date for every single feature, so if the process runs over midnight, the date changes

Best answer by nielsgerrits

I use a Python scripted parameter to do this. I think this is really the best way to do this. In the Navigator, right click on User Parameters, choose Manage  User Parameters, click on the + and choose Scripted. The following code just works, you can reformat the date in the last part if needed.

import datetime
return datetime.datetime.now().strftime("%Y%m%d%H%M%S")

As an alternative you can use a Creator to initiate the workspace, a DateTimeStamper to create a timestamp followed by FeatureReaders to do the rest of the process and keep the _timestamp attribute at all features. This is how I do all my workspaces (Creator + FeatureReader) but dragging the _timestamp attribute through the entire workspace can be a lot of work (lazy dude here) and probably will effect performance in a negative way when handling a lot of features.

 

You also can use a VariableSetter and VariableRetriever's to get the _timestamp before every writer, but these transformers and featurecaching do not always work well together.

View original
Did this help you find an answer to your question?

3 replies

nielsgerrits
VIP
Forum|alt.badge.img+54
  • Best Answer
  • September 13, 2023

I use a Python scripted parameter to do this. I think this is really the best way to do this. In the Navigator, right click on User Parameters, choose Manage  User Parameters, click on the + and choose Scripted. The following code just works, you can reformat the date in the last part if needed.

import datetime
return datetime.datetime.now().strftime("%Y%m%d%H%M%S")

As an alternative you can use a Creator to initiate the workspace, a DateTimeStamper to create a timestamp followed by FeatureReaders to do the rest of the process and keep the _timestamp attribute at all features. This is how I do all my workspaces (Creator + FeatureReader) but dragging the _timestamp attribute through the entire workspace can be a lot of work (lazy dude here) and probably will effect performance in a negative way when handling a lot of features.

 

You also can use a VariableSetter and VariableRetriever's to get the _timestamp before every writer, but these transformers and featurecaching do not always work well together.


hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • September 18, 2023
nielsgerrits wrote:

I use a Python scripted parameter to do this. I think this is really the best way to do this. In the Navigator, right click on User Parameters, choose Manage  User Parameters, click on the + and choose Scripted. The following code just works, you can reformat the date in the last part if needed.

import datetime
return datetime.datetime.now().strftime("%Y%m%d%H%M%S")

As an alternative you can use a Creator to initiate the workspace, a DateTimeStamper to create a timestamp followed by FeatureReaders to do the rest of the process and keep the _timestamp attribute at all features. This is how I do all my workspaces (Creator + FeatureReader) but dragging the _timestamp attribute through the entire workspace can be a lot of work (lazy dude here) and probably will effect performance in a negative way when handling a lot of features.

 

You also can use a VariableSetter and VariableRetriever's to get the _timestamp before every writer, but these transformers and featurecaching do not always work well together.

My preference in scenarios like this is to trigger the workspace with a creator and use a datetimestamper to get one datetime then allow that to flow through the process. To read in features you will need to use feature readers as @nielsgerrits​ has suggested


nicholas
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • October 5, 2023
nielsgerrits wrote:

I use a Python scripted parameter to do this. I think this is really the best way to do this. In the Navigator, right click on User Parameters, choose Manage  User Parameters, click on the + and choose Scripted. The following code just works, you can reformat the date in the last part if needed.

import datetime
return datetime.datetime.now().strftime("%Y%m%d%H%M%S")

As an alternative you can use a Creator to initiate the workspace, a DateTimeStamper to create a timestamp followed by FeatureReaders to do the rest of the process and keep the _timestamp attribute at all features. This is how I do all my workspaces (Creator + FeatureReader) but dragging the _timestamp attribute through the entire workspace can be a lot of work (lazy dude here) and probably will effect performance in a negative way when handling a lot of features.

 

You also can use a VariableSetter and VariableRetriever's to get the _timestamp before every writer, but these transformers and featurecaching do not always work well together.

Thanks, I tried the python scripted parameter and it works


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings