Skip to content

Commit

Permalink
#12 restart only once
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 5, 2024
1 parent c9ee46c commit c6dd238
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/fbe/iterate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,23 @@ def as(label)
@label = label
end

# It makes a number of repeats of going through all repositories
# provided by the "repositories" configuration option. In each "repeat"
# it yields the repository ID and a number that is retrieved by the
# "query". The query is supplied with two parameter:
# "$before" (the value from the previous repeat and "$rid" (the repo ID).
def over(&)
raise 'Use "as" first' if @label.nil?
raise 'Use "by" first' if @query.nil?
seen = {}
oct = Fbe.octo(loog: @loog)
repos = Fbe.unmask_repos(loog: @loog)
restarted = []
loop do
repos.each do |repo|
next if restarted.include?(repo)
seen[repo] = 0 if seen[repo].nil?
if seen[repo] > @repeats
if seen[repo] >= @repeats
@loog.debug("We've seen too many in the #{repo} repo, time to move to the next one")
next
end
Expand All @@ -88,11 +95,12 @@ def over(&)
"(agg (and (eq what '#{@label}') (eq where 'github') (eq repository #{rid})) (first latest))"
).one
Fbe.fb.query("(and (eq what '#{@label}') (eq where 'github') (eq repository #{rid}))").delete!
before = before.nil? ? @since : before[0]
before = before.nil? ? @since : before.first
nxt = Fbe.fb.query(@query).one(before:, repository: rid)
after =
if nxt.nil?
@loog.debug("Next is nil, starting from the beginning at #{@since}")
restarted << repo
@since
else
@loog.debug("Next is #{nxt}, starting from it...")
Expand Down

0 comments on commit c6dd238

Please sign in to comment.