# Best implementation for workflows listening to infrequent signals

**URL:** <https://community.temporal.io/t/best-implementation-for-workflows-listening-to-infrequent-signals/5962>\
**Category:** Community Support\
**Tags:** go-sdk, general-impl, signals\
**Created:** [September 13, 2022, 10:56pm UTC](https://community.temporal.io/t/best-implementation-for-workflows-listening-to-infrequent-signals/5962 "2022-09-13T22:56:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theresa\_Chen](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/theresa_chen/32/2761_2.png) [@Theresa\_Chen](https://community.temporal.io/u/Theresa_Chen)\
**Post date:** [September 13, 2022, 10:56pm UTC](https://community.temporal.io/t/best-implementation-for-workflows-listening-to-infrequent-signals/5962/1 "2022-09-13T22:56:08Z")

</div>

Hello, new user of temporal here. I want to have a continually running workflow the listens to an infrequent signal (approx once a day). Is it sufficient to have a forever running for loop that waits for the signal and executes an activity in response to a signal?

```auto
var mySignal signal
sigChannel := workflow.GetSignalChannel(ctx, mySignal)

for {
sigChannel.Receive(ctx, &mySignal) 
err := workflow.ExecuteActivity(ctx, u.myActivity, mySignal).Get(ctx, nil)
}
return workflow.ContinueAsNew()

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [September 14, 2022, 6:18pm UTC](https://community.temporal.io/t/best-implementation-for-workflows-listening-to-infrequent-signals/5962/3 "2022-09-14T18:18:17Z")

</div>

I think this looks ok. You probably want to return NewContinueAsNewError after X number of received signals and invoked activities.  
You also would need to look at draining the signal channel with continueasnew, see post [here](https://community.temporal.io/t/go-sdk-sequential-by-id-otherwise-in-parallel/1486/5) for more info.

---

<div class="post-metadata">

**Author:** ![krocos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/krocos/32/328_2.png) [@krocos](https://community.temporal.io/u/krocos)\
**Post date:** [September 14, 2022, 6:33pm UTC](https://community.temporal.io/t/best-implementation-for-workflows-listening-to-infrequent-signals/5962/4 "2022-09-14T18:33:39Z")

</div>

Maybe it’s too complicated for the task but

```auto
type SomeSignalYouCanReceiveInThisPhase struct {
	Type string
	Payload string
}

func SomeWorkflow(ctx workflow.Context) error {
	var (
		aa *Activities
		stopSelecting bool
	)

	selector := workflow.NewSelector(ctx)
	sigChannel := workflow.GetSignalChannel(ctx, "my_signals_chan")

	selector.AddReceive(sigChannel, func(ch workflow.ReceiveChannel, more bool) {
		var mySignal SomeSignalYouCanReceiveInThisPhase
		ch.Receive(ctx, &mySignal)

		switch mySignal.Type {
		case "restart_as_new":
			// you can restart as new by the signal
		case "some_special_type_of_signal":
			_ = workflow.ExecuteActivity(ctx, aa.MyActivity, mySignal.Payload).Get(ctx, nil)
		default:
			// break on some reason maybe
			stopSelecting = true
		}
	})

	for {
		if workflow.GetInfo(ctx).GetCurrentHistoryLength() > 50_000 {
			stopSelecting = true
		}

		if stopSelecting {
			break
		}

		selector.Select(ctx)
	}

	return workflow.NewContinueAsNewError(ctx, SomeWorkflow /* we have no params here */)
}

type Activities struct{}

func (aa *Activities) MyActivity(ctx context.Context, somePayload string) error { return nil }

```

Or just that

```auto
sigChannel := workflow.GetSignalChannel(ctx, "name_of_signal_chan")

	for {
		var mySignal signal
		sigChannel.Receive(ctx, &mySignal)
		_ = workflow.ExecuteActivity(ctx, u.myActivity, mySignal).Get(ctx, nil)

		if workflow.GetInfo(ctx).GetCurrentHistoryLength() > 50_000 {
			break
		}
	}

	return workflow.NewContinueAsNewError(ctx, WF)

```
