Skip to content

Any issues putting worker and service api in the same project/pod? #49436

Closed Answered by gfoidl
abratv asked this question in Q&A
Discussion options

You must be logged in to vote

In StopAsync you could disconnect from the queue.
Otherwise it looks good.

For ExecuteAsync -- where basically nothing is to do here, as you also pointed out -- I'd use PeriodicTimer instead:

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    using PeriodicTimer ticker = new(TimeSpan.FromMinutes(1));
        
    while (await ticker.WaitForNextTickAsync(cancellationToken))
    {
        // Log, etc. ...
    }
}

This avoids the repeated allocation of the task in Task.Delay, thus puts less pressure on the GC. Well, here this shouldn't really matter as done only once a minute, but the code is as readable (at least), so that change is just for goodness.

Dependin…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@gfoidl
Comment options

gfoidl Jul 16, 2023
Collaborator

Comment options

You must be logged in to vote
2 replies
@gfoidl
Comment options

gfoidl Jul 17, 2023
Collaborator

Answer selected by abratv
@abratv
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants