LCOV - code coverage report
Current view: top level - server/git - GarbageCollectionRunner.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 17 76.5 %
Date: 2022-11-19 15:00:39 Functions: 5 8 62.5 %

          Line data    Source code
       1             : // Copyright (C) 2014 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.git;
      16             : 
      17             : import com.google.common.collect.Lists;
      18             : import com.google.common.flogger.FluentLogger;
      19             : import com.google.gerrit.extensions.events.LifecycleListener;
      20             : import com.google.gerrit.server.config.GcConfig;
      21             : import com.google.gerrit.server.project.ProjectCache;
      22             : import com.google.inject.Inject;
      23             : 
      24             : /** Runnable to enable scheduling gc to run periodically */
      25             : public class GarbageCollectionRunner implements Runnable {
      26         138 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      27             : 
      28             :   static class Lifecycle implements LifecycleListener {
      29             :     private final WorkQueue queue;
      30             :     private final GarbageCollectionRunner gcRunner;
      31             :     private final GcConfig gcConfig;
      32             : 
      33             :     @Inject
      34         138 :     Lifecycle(WorkQueue queue, GarbageCollectionRunner gcRunner, GcConfig config) {
      35         138 :       this.queue = queue;
      36         138 :       this.gcRunner = gcRunner;
      37         138 :       this.gcConfig = config;
      38         138 :     }
      39             : 
      40             :     @Override
      41             :     public void start() {
      42         138 :       gcConfig.getSchedule().ifPresent(s -> queue.scheduleAtFixedRate(gcRunner, s));
      43         138 :     }
      44             : 
      45             :     @Override
      46             :     public void stop() {
      47             :       // handled by WorkQueue.stop() already
      48         138 :     }
      49             :   }
      50             : 
      51             :   private final GarbageCollection.Factory garbageCollectionFactory;
      52             :   private final ProjectCache projectCache;
      53             : 
      54             :   @Inject
      55             :   GarbageCollectionRunner(
      56         138 :       GarbageCollection.Factory garbageCollectionFactory, ProjectCache projectCache) {
      57         138 :     this.garbageCollectionFactory = garbageCollectionFactory;
      58         138 :     this.projectCache = projectCache;
      59         138 :   }
      60             : 
      61             :   @Override
      62             :   public void run() {
      63           0 :     logger.atInfo().log("Triggering gc on all repositories");
      64           0 :     garbageCollectionFactory.create().run(Lists.newArrayList(projectCache.all()));
      65           0 :   }
      66             : 
      67             :   @Override
      68             :   public String toString() {
      69           0 :     return "GC runner";
      70             :   }
      71             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750