Using the ETLTaskRunId Global Variable

The ETLTaskRunId variable returns identifier of ETL task start that is written into log. It is further available to group operations related with a certain task start in the log.

To get global variable, specify the log, that is necessary for writing loading messages, in properties of the ETL task that uses event handler, otherwise the variable returns -1.

Consider the example of getting the ETLTaskRunId variable in the OnStartTask event of ETL task event handler.

Fore Example

Add links to the Collections, Etl, Ui system assemblies.

Class EventsClass: EtlTaskExecutionEvents
    
    // Event that occurs on ETL task startup
    Public Sub OnStartTask(Task: IEtlTask);
    Var
        App: IApplication;
        Glob: IApplicationGlobals;
        v: Variant;
    Begin
        App := WinApplication.Instance As IApplication;
        Glob := App.Globals;
        v := Glob.Item("ETLTaskRunId");
        WinApplication.InformationBox("The OnStartTask event" + #13 + #10 +
            "Number of ETL task objects = " + Task.Count.ToString + #13 + #10 +
            "Identifier of ETL task start - " + v);
    End Sub OnStartTask;
    
    // Event that occurs on ETL task end
    Public Sub OnEndTask(Task: IEtlTask; Duration, TotalRec, ErrorRec: Integer);
    Begin
        WinApplication.InformationBox("The OnEndTask event" + #13 + #10 +
            "Number of ETL task objects = " + Task.Count.ToString + #13 + #10 +
            "Task execution progress = " + Duration.ToString + #13 + #10 +
            "Number of records at input = " + TotalRec.ToString + #13 + #10 +
            "Number of skipped records at output = " + ErrorRec.ToString);
    End Sub OnEndTask;
    
    // Event that occurs on ETL task block start
    Public Sub OnStartBlock(Task: IEtlTask; Object: IEtlObject);
    Begin
        WinApplication.InformationBox("The OnStartBlock event" + #13 + #10 +
            "Name of ETL task object - " + Task.Item(0).Name + #13 + #10 +
            "ETL task object identifier - " + Object.Id);
    End Sub OnStartBlock;
    
    // Event that occurs on ETL task block end
    Public Sub OnEndBlock(Task: IEtlTask; Object: IEtlObject; Duration: Integer; TotalRecIn, TotalRecOut, ErrorRec: IDictionary);
    Begin
        WinApplication.InformationBox("The OnEndBlock event" + #13 + #10 +
            "Name of ETL task object - " + Task.Item(0).Name + #13 + #10 +
            "ETL task object identifier - " + Object.Id + #13 + #10 +
            "Task execution progress = " + Duration.ToString + #13 + #10 +
            "Number of records at input = " + TotalRecIn.Count.ToString + #13 + #10 +
            "Number of records at input = " + TotalRecOut.Count.ToString + #13 + #10 +
            "Number of skipped records at output = " + ErrorRec.Count.ToString);
    End Sub OnEndBlock;
    
    // Event that occurs during ETL task execution
    Public Sub OnProgress(Task: IEtlTask; Progress: Integer);
    Begin
        WinApplication.InformationBox("The OnProgress event" + #13 + #10 +
            "Name of ETL task object - " + Task.Item(0).Name + #13 + #10 +
            "Task execution progress = " + Progress.ToString);
    End Sub OnProgress;

    // Event that occurs on ETL task block error
    Public Sub OnError(Task: IEtlTask; Object: IEtlObject; Excep: IException);
    Begin
        WinApplication.InformationBox("The OnError event" + #13 + #10 +
            "Name of ETL task object - " + Task.Item(0).Name + #13 + #10 +
            "ETL task object identifier - " + Object.Id + #13 + #10 +
            "Error text - " + Excep.Message);
    End Sub OnError;
    
End Class EventsClass;

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Etl;
Imports Prognoz.Platform.Interop.ForeCollections;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ui;
Imports System.Windows.Forms;

Public Class EventsClass: EtlTaskExecutionEvents
    
    // Event that occurs on ETL task start
    Public Sub OnStartTask(Task: IEtlTask);
    Var
        App: IApplication;
        Glob: IApplicationGlobals;
        v: object;
        WinApplication: WinApplicationClassClass = New WinApplicationClassClass();
    Begin
        App := WinApplication.Instance[NullAs IApplication;
        Glob := App.Globals;
        v := Glob.Item["ETLTaskRunId"];
        MessageBox.Show("The OnStartTask event" + "u000d\u000a" +
            "Number of ETL task objects = " + Task.Count.ToString() + "u000d\u000a" +
            "Identifier of ETL task start - " + v);
    End Sub OnStartTask;
    
    // Event that occurs on ETL task end
    Public Sub OnEndTask(Task: IEtlTask; Duration, TotalRec, ErrorRec: Integer);
    Begin
        MessageBox.Show("The OnEndTask event" + "u000d\u000a" +
            "Number of ETL task objects = " + Task.Count.ToString() + "u000d\u000a" +
            "Task execution result = " + Duration.ToString() + "u000d\u000a" +
            "Number of records at input = " + TotalRec.ToString() + "u000d\u000a" +
            "Number of skipped records at output = " + ErrorRec.ToString());
    End Sub OnEndTask;
    
    // Event that occurs on ETL task block start
    Public Sub OnStartBlock(Task: IEtlTask; Object: IEtlObject);
    Begin
        MessageBox.Show("The OnStartBlock event" + "u000d\u000a" +
            "ETL task object name - " + Task.Item[0].Name + "u000d\u000a" +
            "ETL task object identifier - " + Object.Id);
    End Sub OnStartBlock;
    
    // Event that occurs on finishing ETL task block
    Public Sub OnEndBlock(Task: IEtlTask; Object: IEtlObject; Duration: integer; TotalRecIn, TotalRecOut, ErrorRec: IDictionary);
    Begin
        MessageBox.Show("The OnEndBlock event" + "u000d\u000a" +
            "ETL task object name - " + Task.Item[0].Name + "u000d\u000a" +
            "ETL task object identifier - " + Object.Id + "u000d\u000a" +
            "Task execution result = " + Duration.ToString() + "u000d\u000a" +
            "Number of records at input = " + TotalRecIn.Count.ToString() + "u000d\u000a" +
            "Number of records at input = " + TotalRecOut.Count.ToString() + "u000d\u000a" +
            "Number of skipped records at output = " + ErrorRec.Count.ToString());
    End Sub OnEndBlock;
    
    // Event that occurs during ETL task execution
    Public Sub OnProgress(Task: IEtlTask; Progress: Integer);
    Begin
        MessageBox.Show("The OnProgress event" + "u000d\u000a" +
            "ETL task object name - " + Task.Item[0].Name + "u000d\u000a" +
            "Task execution progress = " + Progress.ToString());
    End Sub OnProgress;

    // Event that occurs on ETL task block error
    Public Sub OnError(Task: IEtlTask; Object: IEtlObject; Excep: Exception);
    Begin
        MessageBox.Show("The OnError event" + "u000d\u000a" +
            "ETL task object name - " + Task.Item[0].Name + "u000d\u000a" +
            "ETL task object identifier - " + Object.Id + "u000d\u000a" +
            "Error text - " + Excep.Message);
    End Sub OnError;
    
End Class EventsClass;

See also:

Examples