Skip to main content
Hi all,

 

 

Kindly asking for suggestion if anyone had found a solution for such an issue:

 

in theory, getting job_id during python shutdown script execution should be piece of cake, with accessing to FME_MacroValuesu'FME_JOB_ID'],

 

but actually there is no such key in FME_MacroValues. I've explored all FME_MacroValues dictionary, nothing similar is there.

 

Also, there is nothing that could help in globals() as well.

 

 

Is actually FME server still providing job_id for python hooks executed on start/end of translation?
Hi,

 

 

it seems it is still documented, for what it's worth. It might be that the value is undefined after the workspace terminates its processing.

 

 

Do you get the value if you access FME_MacroValuesa'FME_JOB_ID'] from a PythonCaller? If so, you could write out the value to a global Python variable and later retrieve it during your shutdown script.

 

 

David
no success with PythonCaller either.

 

code:

 

    global my_glob_job_id

 

    try:

 

        my_glob_job_id = FME_MacroValues['FME_JOB_ID']

 

    except:

 

        my_glob_job_id = 'no_job_id_access'

 

 

and in shutdown script i have 'no_job_id_access' for my_glob_job_id
Hi,

 

 

just to verify: you're running this from FME Server, right? I'm asking since FME_JOB_ID isn't available from FME Desktop.

 

 

If you still can't get it to work, I'd consider sending the issue to Safe.

 

 

David
yes, from server,

 

FME Server 2013 / linux

 

 

thanks David,

 

seems it really better first to clarify with Safe that server provide job_id at runtime.
The job_id is not available to the shutdown script.

 

 

One method that I've employed in the past is to write the job ID to the log file when the translation is running and then read it back out in the shutdown script.

 

 

Here's my python function for parsing the log file:

 

 

# Searches the log file for attribute values and returns them as a list.

 

#

 

# Attribute values are expected to be written to the log file, one per line, in the

 

# format:

 

#   __logAttr_<attrName>:<attrValue>

 

# e.g.

 

#   __logAttr_JOB_ID:99

 

#

 

def ParseAttrsFromLogfile():

    # Get a handle on the log file

 

    logFileName = FME_LogFileName

    attrs = {}

 

    allText = open(logFileName, 'rb').read()  # read whole log file into 1 string

 

    rex = re.compile(r'__logAttr_(Â^:\\s]+):(.+)\\r', re.I | re.M)

 

    rslts = rex.finditer(allText)

 

    for rslt in rslts:

 

        if rslt.group(1):

 

            attrs rslt.group(1)] = rslt.group(2)

 

    return attrs

 

To write an attribute to the log file during the translation I had to use the TCLCaller transformer (I wasn't able to do it with Python).

 

 

My TCL proc for writing the attributes to the log file is below. This proc assumes that the names of the attributes to log are a comma-seperated list in a feature attribute called "_ATTRS_TO_LOG":

 

 

proc LogAttributes {} {

 

   

 

    set attrNames >split >FME_GetAttribute _ATTRS_TO_LOG] ,];

 

    #FME_LogMessage fme_inform __LOGGED_ATTRS:tFME_GetAttribute _ATTRS_TO_LOG];

    foreach attrName $attrNames {

 

        set aName tstring trim $attrName];

 

        FME_LogMessage fme_inform __logAttr_$aName:ÂFME_GetAttribute $aName];

 

    };

 

}

 

 Good luck!

 

 
Hi, It works for me on Windows, build 13450 (service pack 1).

 

I believe this was added in sp1, could your server-side FME Engine perhaps have an earlier build (check first line of server-log-file)?

 

 

/Peter
thanks all,

 

FME_JOB_ID added in FME 2013 SP1 and there was no available in 2013 release. Updating to latest build helps.

 

thank you all for suggestions

 


Reply