Skip to content

[Proposal] Notify runners to fetch Actions tasks instead of polling #24543

Open
@wolfogre

Description

@wolfogre

Background

Act runner connects to the Gitea instance via short HTTP connections. So runners have to ask for new task again and again.

Gitea will start a transaction to find and assign a task to the runner when it requests a new one. However, we know that there may not be a task available most of the time, so Gitea has to roll back the transaction and respond with "no task yet, try again later."

That’s why you can see there are so many POST /api/actions/runner.v1.RunnerService/FetchTask in router logs, and [SQL] ROLLBACK [] in SQL logs.

It doesn't hurt but it's annoying. And it wastes network and database resources to some extent.

Solution

Provides a mechanism for Gitea to notify runners

We need a way to notify runners from the Gitea side. Here are some possible ways:

  • gRPC Streaming. Not sure if it works with gRPC over HTTP.
  • WebSocket. Actually, it was used in earlier versions of Gitea Actions.
  • Blocking Queries. It's the way in which the consul watches changes.
  • Server-sent events.

I'm not sure which approach would be best. However, one thing is certain: the approach must be compatible with the proxy. This is because there is always an HTTP proxy in front of Gitea, such as Nginx. IIRC, Nginx with default config closes connections that have been inactive for a long time.

Reuse old logic to fetch task

To be clear, Gitea will notify runners only with a simple message "there may be a new task", instead of the whole task data.

So it could be easier to implement, whenever the relevant data table changes, Gitea could notify all runners. The runners will then request new tasks, just as they do now. If they don't get a new task, maybe the label does’t match, they can just continue to wait to be notified again.

On the other hand, runners may not immediately request new tasks when notified because they may already be at capacity, and they will request later when they are idle.

Therefore, forcefully sending tasks to runners without their request may not be feasible or may be very complicated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic/gitea-actionsrelated to the actions of Giteatype/proposalThe new feature has not been accepted yet but needs to be discussed first.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions