Skip to content
Permalink
Browse files
[JENKINS-32190] Make UsageStatistics#isDue check Jenkins init level b…
…efore generating stats.

(cherry picked from commit d8a13ac)
  • Loading branch information
Andres Rodriguez authored and olivergondza committed Feb 3, 2016
1 parent e1a92ce commit 50b927c7fcb148ee08959d7d68b11afa40de9e15
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 50b927c

Please sign in to comment.