From 7f6e9e636c378978082200e2aa5342c43bba8a51 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 25 May 2022 09:24:01 +0200 Subject: [PATCH] fix(cron): retrieve all GitRepo's instead of first 25 --- src/client/git.v | 23 ++++++++++++++++++++++- src/cron/daemon/daemon.v | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/client/git.v b/src/client/git.v index fd14718d..4496c08a 100644 --- a/src/client/git.v +++ b/src/client/git.v @@ -4,7 +4,7 @@ import models { GitRepo, GitRepoFilter } import net.http { Method } import response { Response } -// get_git_repos returns the current list of repos. +// get_git_repos returns a list of GitRepo's, given a filter object. pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo { params := models.params_from(filter) data := c.send_request<[]GitRepo>(Method.get, '/api/repos', params)? @@ -12,6 +12,27 @@ pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo { return data.data } +// get_all_git_repos retrieves *all* GitRepo's from the API using the default +// limit. +pub fn (c &Client) get_all_git_repos() ?[]GitRepo { + mut repos := []GitRepo{} + mut offset := u64(0) + + for { + sub_repos := c.get_git_repos(offset: offset)? + + if sub_repos.len == 0 { + break + } + + repos << sub_repos + + offset += u64(sub_repos.len) + } + + return repos +} + // get_git_repo returns the repo for a specific ID. pub fn (c &Client) get_git_repo(id int) ?GitRepo { data := c.send_request(Method.get, '/api/repos/$id', {})? diff --git a/src/cron/daemon/daemon.v b/src/cron/daemon/daemon.v index 82c219de..f1206d6d 100644 --- a/src/cron/daemon/daemon.v +++ b/src/cron/daemon/daemon.v @@ -178,7 +178,7 @@ fn (mut d Daemon) schedule_build(repo GitRepo) { fn (mut d Daemon) renew_repos() { d.linfo('Renewing repos...') - mut new_repos := d.client.get_git_repos() or { + mut new_repos := d.client.get_all_git_repos() or { d.lerror('Failed to renew repos. Retrying in ${daemon.api_update_retry_timeout}s...') d.api_update_timestamp = time.now().add_seconds(daemon.api_update_retry_timeout)