What's the es-states, can't find it in git_mirror.rb?
On Tue, Jan 19, 2021 at 09:53:46AM +0800, Li Yuanchao wrote:
When init fork_stat{}, first query the es, get states in es if there is.
|| query stats in es at first?
Thanks, Xueliang
So historical data can be kept.
Signed-off-by: Li Yuanchao lyc163mail@163.com
lib/git_mirror.rb | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 86f02e5..1109cfe 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,31 @@ class MirrorMain
handle_submodule(submodule)
end
- def copy_from_es(es_data)
- fork_stat = {}
- fork_stat[:queued] = es_data['queued']
- fork_stat[:priority] = es_data['priority']
- fork_stat[:fetch_time] = es_data['fetch_time']
- fork_stat[:offset_fetch] = es_data['offset_fetch']
- fork_stat[:new_refs_time] = es_data['new_refs_time']
- fork_stat[:offset_new_refs] = es_data['offset_new_refs']
- return fork_stat
- end
- def get_fork_stat(git_repo)
- query = { query: { match: { git_repo: git_repo } } }
- result = @es_client.search(index: 'repo', body: query)['hits']
- return copy_from_es(result['hits'][0]['_source']) if result['total'].positive?
- fork_stat = {
queued: false,
priority: 0,
fetch_time: [],
offset_fetch: 0,
new_refs_time: [],
offset_new_refs: 0
- }
- return fork_stat
- end
end
2.23.0