When Gitea starts, it initializes the mirror service which creates the “mirror” queue singleton which runs in a RunWithShutdownFns goroutine. The “mirror” queue is created by CreateUniqueQueue via NewQueue and is backed by a persistent storage. It handles retries, timeouts etc.
The queueHandle function is called when a new SyncRequest is pushed to the queue. It calls either SyncPullMirror or SyncPushMirror to perform the mirroring and schedules the next run by updating the LastUpdateUnix database field (date and time). When the Update function runs from cron every 10 minutes, it iterates on the database records and runs the handler when it is due.
The handler does not perform the action, it pushes a SyncRequest onto the “mirror” queue and it will be passed on to the queueHandle function that was registered when the “mirror” queue was initialized. There can only be one
SyncPushMirror for a given repository in the queue. That’s what the “Unique” in “UniqueQueue” stands for: the redis unique queue enforces this constraint by using SADD and failing on duplicate entries.