func (d *decision) emailError(reason string) (string, error) {
	runid := strings.Replace(d.runid, "=", "!=", 1)
	msg := "https://console.aws.amazon.com/swf/home?region=us-east-1#execution_events:domain=" + swfDomain + ";workflowId=" + d.workflowid + ";runId=" + runid
	err := amazon.SESSendEmail("*****@*****.**", helpdesk, "Workflow "+reason+" Occured", msg)
	if err != nil {
		return "", err
	}
	Info.Printf("Error emailed to %v", helpdesk)
	return helpdesk, nil
}
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")
		}
	}
}