Skip to content

Commit

Permalink
[JENKINS-32190] Make UsageStatistics#isDue check Jenkins init level b…
Browse files Browse the repository at this point in the history
…efore generating stats.

(cherry picked from commit d8a13ac)
  • Loading branch information
Andres Rodriguez authored and olivergondza committed Feb 3, 2016
1 parent e1a92ce commit 50b927c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/main/java/hudson/model/UsageStatistics.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 50b927c

Please sign in to comment.