func main() { flag.BoolVar(&stdout, "stdout", false, "Log to stdout") flag.Parse() // initialise logs Info, Error = file.InitLogs(stdout, "/var/rapiddecider", "rapiddecider") Info.Println("Starting rapiddecider =================>") // start workflow swfsvc := swf.New(session.New(), &aws.Config{Region: aws.String("us-east-1")}) params := &swf.PollForDecisionTaskInput{ Domain: aws.String(swfDomain), // TaskList: &swf.TaskList{ // Name: aws.String(swfTasklist), // }, Identity: aws.String(swfIdentity), MaximumPageSize: aws.Int64(100), ReverseOrder: aws.Bool(true), } // loop forever while polling for work for { resp, err := swfsvc.PollForDecisionTask(params) if err != nil { amazon.SESSendEmail("*****@*****.**", helpdesk, swfIdentity+" unable to pole", err.Error()) Error.Printf("error: unable to poll for decision: %v\n", err) //panic("Broken, check logs") } // if we do not receive a task token then 60 second time out occured so try again if resp.TaskToken != nil { if *resp.TaskToken != "" { // Re-initialise logs so we get latest date Info, Error = file.InitLogs(stdout, "/var/rapiddecider", "rapiddecider") d := &decision{ svc: swfsvc, tt: *resp.TaskToken, runid: *resp.WorkflowExecution.RunId, workflowid: *resp.WorkflowExecution.WorkflowId, } // make each decision in a goroutine which means that multiple decisions can be made go d.makeDecision(resp.Events, resp.WorkflowExecution.RunId) } } else { Info.Printf("debug - no decisions required\n") } } }
// ===================== Generic code ====================== // Below is here for legacy purposes, should eventually use our tools, (as pioneer) func main() { //_ = "breakpoint" // Get starting flags flag.BoolVar(&stdout, "stdout", false, "Log to stdout") flag.StringVar(¤tfolder, "folder", "", "Set current folder") flag.Parse() // initialise logs Info, Error = file.InitLogs(stdout, logfolder, swfTasklist) Info.Println("Starting " + swfIdentity + " Version:" + Version + " ==>") // Load properties json file Info.Println("Loading properties from " + filepath.Join(currentfolder, "rclinvoices.json")) props, err := file.LoadProperties(filepath.Join(currentfolder, "rclinvoices.json")) if err != nil { Error.Fatal("Could not load properties" + filepath.Join(currentfolder, "rclinvoices.json")) return } swfTasklist = file.GetProperty(props, "supplierid") // Initialise workflow swfsvc := swf.New(session.New(), &aws.Config{Region: aws.String("us-east-1")}) params := &swf.PollForActivityTaskInput{ Domain: aws.String(swfDomain), // TaskList: &swf.TaskList{ // Name: aws.String(swfTasklist), // }, Identity: aws.String(swfIdentity), } Info.Println(params) // loop forever while polling for work x := 0 for { resp, err := swfsvc.PollForActivityTask(params) if err != nil { Error.Fatalf("error: unable to poll for decision: %v\n", err) } // if we do not receive a task token then 60 second time out occured so try again //_ = "breakpoint" if resp.TaskToken != nil { if *resp.TaskToken != "" { a := &activity{ svc: swfsvc, tt: *resp.TaskToken, input: *resp.Input, name: *resp.ActivityType.Name, } result, details, err := a.handleActivity() if err != nil { Info.Printf("Error sending POD: \n" + a.input) a.taskFailed(err.Error(), details) } else { Info.Println("Task completed OK") a.taskCompleted(result) } } } else { // Every 20 minutes check in, just so we have some log activity x++ if x == 20 { Info.Printf("debug - no activity required\n") x = 0 } } } }