Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SaveableListener#onDeleted #9743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Vlatombe
Copy link
Member

@Vlatombe Vlatombe commented Sep 17, 2024

Usually Saveable objects are written, but it can happen on occasion that they get deleted, and it wasn't generating an event for every case.

This provides a more fine-grained event that can be handled by implemented listeners.

In my case, I have a use case in CloudBees CI where I need to clear a cache entry when a Saveable gets deleted from disk.

See JENKINS-XXXXX.

Testing done

Proposed changelog entries

  • developer: A new method SaveableListener#onDeleted can be implemented by plugins to be notified about Saveable deletion.

Proposed upgrade guidelines

N/A

Submitter checklist

Desired reviewers

@mention

Before the changes are marked as ready-for-merge:

Maintainer checklist

Usually `Saveable` objects are written, but it can happen on occasion that they get deleted, and it wasn't generating an event for every case.

This provides a more fine-grained event that can be handled by implemented listeners.

In my case, I have a use case in CloudBees CI where I need to clear a cache entry when a Saveable gets deleted from disk.
@Vlatombe Vlatombe added the developer Changes which impact plugin developers label Sep 17, 2024
@Vlatombe Vlatombe requested review from jglick and a team September 17, 2024 12:29
Logger.getLogger(SaveableListener.class.getName()).log(Level.WARNING, null, t);
}
}
Listeners.notify(SaveableListener.class, false, l -> l.onChange(o, file));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the false is crucial here for things like auditing.

@@ -556,7 +556,7 @@ public void delete() throws IOException {
loggers.forEach(Target::disable);

getParent().getRecorders().forEach(logRecorder -> logRecorder.getLoggers().forEach(Target::enable));
SaveableListener.fireOnChange(this, getConfigFile());
SaveableListener.fireOnDeleted(this, getConfigFile());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incompatible, I guess, but unlikely to be a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess it is unlikely enough.

@@ -815,6 +815,7 @@ public void delete() throws IOException, InterruptedException {
ItemDeletion.deregister(this);
}
}
SaveableListener.fireOnDeleted(this, getConfigFile());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A related oddity FTR: #9304 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer Changes which impact plugin developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants