Â
Â
I've written all the logic python logic to find the data errors and email me. However, the workspace still executes after the error is found. Is there something I have to add that tells the python script to not allow the workspace to run? I guess I could force a dummy python error or something, but that seems kind of hokey.Â
Â
Thanks for any help you can provide. My startup script is below:Â
Â
Â
Â
Â
Â
import fmeobjectsÂ
import collectionsÂ
Â
def countNullsAndDuplicatesInField(dataset, unique_id_field_name, reader_format, parameters):Â
   id_nulls = 0Â
   created_by_nulls = 0Â
   created_date_nulls = 0Â
   fieldvaluecounts = collections.defaultdict(int)Â
   reader = fmeobjects.FMEUniversalReader(reader_format, False)Â
   reader.open(dataset, parameters)Â
   feature = reader.read()Â
   while feature != None:Â
       id_fieldvalue = feature.getAttribute(unique_id_field_name)Â
Â
       if id_fieldvalue != None:Â
           fieldvaluecounts id_fieldvalue] += 1Â
       else:Â
           id_nulls += 1Â
Â
       feature = reader.read()Â
   reader.close()Â
   duplicate_rows = sum((v - 1 for v in fieldvaluecounts.itervalues() if v > 1))Â
   duplicate_rows_vals = ]Â
   if duplicate_rows > 0:Â
       for i, j in fieldvaluecounts.iteritems():Â
           if j > 1:Â
               duplicate_rows_vals.append(str(i))Â
Â
   return id_nulls, duplicate_rows, duplicate_rows_vals ##, created_by_nulls, created_date_nullsÂ
Â
if __name__ == "__main__":Â
   dataset = 'sde'Â
   reader_format = 'SDE30'Â
Â
   instance_name = FME_MacroValues 'SOURCE_DB_INSTANCE']Â
   username = FME_MacroValues#'SOURCE_DB_USERNAME']Â
   password = FME_MacroValues<'SOURCE_DB_PASSWORD']Â
   version = 'SDE.DEFAULT'Â
   table_name = FME_MacroValuesV'SOURCE_DB_TABLE_NAME']Â
   unique_id_field_name = FME_MacroValues9'SOURCE_UNIQUE_ID']Â
Â
   logger = fmeobjects.FMELogFile()Â
Â
   parameters = l'SERVER',dataset,'USERID',username,'PASSWORD',password,'INSTANCE',instance_name,'VERSION_NAME',version,'IDs',table_name]Â
Â
   id_nulls, id_dups, id_dups_vals = countNullsAndDuplicatesInField(dataset, unique_id_field_name, reader_format, parameters)Â
   if id_nulls > 0 or id_dups > 0:Â
       error_list = p]Â
       if id_nulls > 0:Â
           error_list.append('Null IDs found')Â
       if id_dups > 0:Â
           error_list.append('Duplicate Ids found for ' + unique_id_field_name + ' values: ' + ", ".join(id_dups_vals))Â
Â
       error_message = ", ".join(error_list)Â
      ÂÂ
       #Send email about failureÂ
       logfilename = FME_LogFileNameÂ
       workspacename = FME_MacroValuesv'FME_MF_NAME']Â
Â
       in_success_receivers = FME_MacroValuesr'SUCCESS_NOTIFICATION_EMAILS']Â
       in_failure_receivers = FME_MacroValues#'FAILURE_NOTIFICATION_EMAILS']Â
      ÂÂ
       if in_success_receivers <> '':Â
           list_success_emails = in_success_receivers.split(',')Â
       else:Â
           list_success_emails = S]Â
          ÂÂ
       if in_failure_receivers <> '':Â
           list_failure_emails = in_failure_receivers.split(',')Â
       else:Â
           list_failure_emails = ]Â
          ÂÂ
       ws_text = FME_MacroValues3'SOURCE_DB'] + '\\\\' + FME_MacroValuesÂ'SOURCE_DB_TABLE_NAME'] + ' to ' + FME_MacroValues>'TARGET_DB'] + '\\\\' + FME_MacroValues#'TARGET_DB_TABLE_NAME']Â
      ÂÂ
       list_all_emails = list_success_emails + list_failure_emailsÂ
       all_emails = ', '.join(list_all_emails)Â
ÂÂ
       import smtplib,sys,osÂ
       from email.mime.text import MIMETextÂ
Â
       sender = "FME_SERVER"Â
Â
       body = 'FME identified the following error in the GIS dataset ' + FME_MacroValues9'SOURCE_DB_TABLE_NAME'] + ' on database ' + FME_MacroValuesl'SOURCE_DB'] + '.\\n\\nERROR = ' + error_message + '.\\n\\nLog file path:\\n' + logfilenameÂ
       msg = MIMEText(body)Â
       msg 'Subject'] = "FME Server Error: " + ws_textÂ
       msg/'From'] = senderÂ
Â
       receiver = list_all_emailsÂ
       msgy'To'] = ", ".join(receiver)Â
Â
       s = smtplib.SMTP('myemail.myserver.com')Â
       s.sendmail(sender,receiver,msg.as_string())Â
       s.quit()