Skip to content

Commit

Permalink
Use AutoValue for ActionProgressEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Jun 11, 2021
1 parent cb73b06 commit 78b1d95
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
package com.google.devtools.build.lib.actions;

import com.google.auto.value.AutoValue;
import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike;

/**
* Notifies that an in-flight action is making progress.
*/
public class ActionProgressEvent implements ProgressLike {
private final ActionExecutionMetadata action;
private final String progressId;
private final String progress;
private final boolean isFinished;
/** Notifies that an in-flight action is making progress. */
@AutoValue
public abstract class ActionProgressEvent implements ProgressLike {

public ActionProgressEvent(ActionExecutionMetadata action, String progressId, String progress, boolean isFinished) {
this.action = action;
this.progressId = progressId;
this.progress = progress;
this.isFinished = isFinished;
public static ActionProgressEvent create(
ActionExecutionMetadata action, String progressId, String progress, boolean finished) {
return new AutoValue_ActionProgressEvent(action, progressId, progress, finished);
}

/** Gets the metadata associated with the action being scheduled. */
public ActionExecutionMetadata getActionMetadata() {
return action;
}
public abstract ActionExecutionMetadata action();

/**
* The id that uniquely determines the progress among all progress events within an action.
*/
public String getProgressId() {
return progressId;
}
/** The id that uniquely determines the progress among all progress events within an action. */
public abstract String progressId();

/** Human readable description of the progress */
public String getProgress() {
return progress;
}
public abstract String progress();

/** Whether the download progress reported about is finished already */
public boolean isFinished() {
return isFinished;
}
public abstract boolean finished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public static SpawnProgressEvent create(String resourceId, String progress, bool

@Override
public void postTo(ExtendedEventHandler eventHandler, ActionExecutionMetadata action) {
eventHandler.post(new ActionProgressEvent(action, progressId(), progress(), finished()));
eventHandler.post(ActionProgressEvent.create(action, progressId(), progress(), finished()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ synchronized void setRunning(String strategy, long nanoChangeTime) {
* Handle the progress event for the action.
*/
synchronized void onProgressEvent(ActionProgressEvent event, long nanoChangeTime) {
String id = event.getProgressId();
if (event.isFinished()) {
String id = event.progressId();
if (event.finished()) {
// a download is finished, clean it up
runningProgress.remove(id);
progressNanoStartTimes.remove(id);
Expand Down Expand Up @@ -566,8 +566,8 @@ void runningAction(RunningActionEvent event) {
}

void actionProgress(ActionProgressEvent event) {
ActionExecutionMetadata action = event.getActionMetadata();
Artifact actionId = event.getActionMetadata().getPrimaryOutput();
ActionExecutionMetadata action = event.action();
Artifact actionId = event.action().getPrimaryOutput();
long now = clock.nanoTime();
getActionState(action, actionId, now).onProgressEvent(event, now);
}
Expand Down Expand Up @@ -1136,7 +1136,7 @@ private void reportOneActionProgress(
long nanoDownloadTime = nanoTime - actionState.progressNanoStartTimes.get(id);
long downloadSeconds = nanoDownloadTime / NANOS_PER_SECOND;

String progress = download.getProgress();
String progress = download.progress();
if (progress.isEmpty()) {
progress = id;
}
Expand Down

0 comments on commit 78b1d95

Please sign in to comment.