github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/engine/engine.go (about)

     1  package engine
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/mdaxf/iac/engine/trancode"
     8  	"github.com/mdaxf/iac/engine/types"
     9  	"github.com/mdaxf/iac/logger"
    10  )
    11  
    12  type Engine struct {
    13  	trancode        types.TranCode
    14  	externalinputs  map[string]interface{} // {sessionanme: value}
    15  	externaloutputs map[string]interface{} // {sessionanme: value}
    16  	systemsessions  map[string]interface{} // {sessionanme: value}
    17  }
    18  
    19  func NewEngine(trancode types.TranCode, systemSession map[string]interface{}) *Engine {
    20  	//systemSession := make(map[string]interface{})
    21  	systemSession["UTCTime"] = time.Now().UTC()
    22  	systemSession["LocalTime"] = time.Now()
    23  	if systemSession["UserNo"] == nil {
    24  		systemSession["UserNo"] = "System"
    25  	}
    26  	if systemSession["UserID"] == nil {
    27  		systemSession["UserID"] = 0
    28  	}
    29  
    30  	if systemSession["WorkSpace"] == nil {
    31  		systemSession["WorkSpace"] = ""
    32  	}
    33  	if systemSession["ClientID"] == nil {
    34  		systemSession["ClientID"] = ""
    35  	}
    36  
    37  	return &Engine{
    38  		trancode:        trancode,
    39  		externalinputs:  map[string]interface{}{},
    40  		externaloutputs: map[string]interface{}{},
    41  		systemsessions:  systemSession,
    42  	}
    43  
    44  }
    45  
    46  func (e *Engine) Execute() {
    47  	iLog := logger.Log{ModuleName: logger.TranCode, User: e.systemsessions["UserNo"].(string), ControllerName: "TranCode.Engine"}
    48  
    49  	startTime := time.Now()
    50  	defer func() {
    51  		elapsed := time.Since(startTime)
    52  		iLog.PerformanceWithDuration("engine.TranCode.compareMap", elapsed)
    53  	}()
    54  	defer func() {
    55  		if r := recover(); r != nil {
    56  			iLog.Error(fmt.Sprintf("Error in Trancode.compareMap: %s", r))
    57  			return
    58  		}
    59  	}()
    60  
    61  	tf := trancode.NewTranFlow(e.trancode, e.externalinputs, e.systemsessions, nil, nil)
    62  	_, err := tf.Execute()
    63  	if err != nil {
    64  		iLog.Error(fmt.Sprintf("Execute the trancode error: %v", err.Error()))
    65  	}
    66  }