Handling interruption/stop running on the worker service

I had an issue when worker I stop it and rerun it … with this code …

	selector := workflow.NewSelector(ctx)

	newDuration := req.Times.Sub(time.Now().Local())
	timerFuture := workflow.NewTimer(ctx, newDuration)
	selector.AddFuture(timerFuture, func(f workflow.Future) {
		errExe := workflow.ExecuteActivity(ctx, libs.ActivityGeneral, req).Get(ctx, &resp)
		if errExe != nil {
			errorStr := strings.Split(errExe.Error(), "):")
			if strings.TrimSpace(errorStr[1]) == libs.FailedMethod || strings.TrimSpace(errorStr[1]) == libs.FailedTask {
				err = errExe
			} else {
				execution := workflow.GetInfo(ctx).WorkflowExecution
				childID := fmt.Sprintf("retry_workflow:%v", execution.RunID)
				cwo := workflow.ChildWorkflowOptions{
					WorkflowID: childID,
				}
				ctx = workflow.WithChildOptions(ctx, cwo)
				errChild := workflow.ExecuteChildWorkflow(ctx, RetryWorkflow, req).Get(ctx, &resp)
				if errChild != nil {
					qoingohelper.LoggerError(errChild)
					err = errChild
				}
			}

		}
	})

	ctx = actvityOption(ctx, req)

	selector.Select(ctx)

	return

I give it like a time delay for a minute , in the middle of a time i stop the worker and run it again
, its giving me an error “nondeterministic workflow definition code or incompatible change in the workflow definition” …
do I wrong using selector , or any solution …
if worker running without interruption , worker will be fine …

Seems you are using system time, which is not deterministic. Try using workflow.Now(ctx) instead to get the current time inside workflow code.

@tihomir is correct that your code is non deterministic.

BTW there is no need to use Selector to listen on a single Future. Future.Get(…) is already a blocking call.

thanks for replying, ok, I will try to change code without using selector