Everytime git-mirror get new_refs or just git fetch, these actions and the time will be recorded in hash fork_stat{}. But when container git-mirror restart, fork_stat{} will be initialized. So historical data can't be kept.
Now, git-mirror will get historical data from es when initialize hash fork_stat{}. So historical data will be kept.
Signed-off-by: Li Yuanchao lyc163mail@163.com --- lib/git_mirror.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 86f02e5..4f74751 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -109,15 +109,8 @@ class MirrorMain @webhook_queue = channel.queue('web_hook') end
- def fork_stat_init(stat_key) - @fork_stat[stat_key] = { - queued: false, - priority: 0, - fetch_time: [], - offset_fetch: 0, - new_refs_time: [], - offset_new_refs: 0 - } + def fork_stat_init(git_repo) + @fork_stat[git_repo] = get_fork_stat(git_repo) end
def load_defaults(repodir) @@ -372,4 +365,23 @@ class MirrorMain
handle_submodule(submodule) end + + def get_fork_stat(git_repo) + fork_stat = { + queued: false, + priority: 0, + fetch_time: [], + offset_fetch: 0, + new_refs_time: [], + offset_new_refs: 0 + } + query = { query: { match: { git_repo: git_repo } } } + result = @es_client.search(index: 'repo', body: query)['hits'] + return fork_stat unless result['total'].positive? + + fork_stat.each_key do |key| + fork_stat[key] = result['hits'][0]['_source'][key.to_s] + end + return fork_stat + end end