Skip to content
Permalink
Browse files
[JENKINS-32190] Make UsageStatistics#isDue check Jenkins init level b…
…efore generating stats.
  • Loading branch information
Andres Rodriguez committed Jan 11, 2016
1 parent 9ab3f1d commit d8a13ac07c4357eb74ab45a03955c0db430e3aa9
Showing with 7 additions and 3 deletions.
  1. +7 −3 core/src/main/java/hudson/model/UsageStatistics.java
@@ -31,6 +31,7 @@
import hudson.util.IOUtils;
import hudson.util.Secret;
import static hudson.util.TimeUnit2.DAYS;
import static hudson.init.InitMilestone.COMPLETED;

import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
@@ -95,9 +96,12 @@ public UsageStatistics(String keyImage) {
* Returns true if it's time for us to check for new version.
*/
public boolean isDue() {
// user opted out. no data collection.
if(!Jenkins.getInstance().isUsageStatisticsCollected() || DISABLED) return false;

final Jenkins j = Jenkins.getInstance();
// user opted out or Jenkins not fully initialized. no data collection.
if (j == null || j.isUsageStatisticsCollected() || DISABLED || COMPLETED.compareTo(j.getInitLevel()) > 0) {
return false;
}

long now = System.currentTimeMillis();
if(now - lastAttempt > DAY) {
lastAttempt = now;

0 comments on commit d8a13ac

Please sign in to comment.