Skip to content

Add SynchronousNonBlockingStepExecutorServiceAugmentor #226

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package org.jenkinsci.plugins.workflow.steps;

import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.util.ClassLoaderSanityThreadFactory;
import hudson.util.DaemonThreadFactory;
import hudson.util.NamingThreadFactory;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import edu.umd.cs.findbugs.annotations.NonNull;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.springframework.security.core.Authentication;

/**
Expand Down Expand Up @@ -92,9 +95,26 @@ public void onResume() {

static synchronized ExecutorService getExecutorService() {
if (executorService == null) {
executorService = Executors.newCachedThreadPool(new NamingThreadFactory(new ClassLoaderSanityThreadFactory(new DaemonThreadFactory()), "org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution"));
ExecutorService result = Executors.newCachedThreadPool(new NamingThreadFactory(new ClassLoaderSanityThreadFactory(new DaemonThreadFactory()), "org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution"));

for (ExecutorServiceAugmentor augmentor : ExtensionList.lookup(ExecutorServiceAugmentor.class)) {
result = augmentor.augment(result);
}
executorService = result;
}
return executorService;
}

/**
* Extension point for augmenting the executorService of {@link SynchronousNonBlockingStepExecution}.
Copy link
Member

@dwnusbaum dwnusbaum Jul 1, 2025

Choose a reason for hiding this comment

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

Might need an import for this, not sure.

Suggested change
* Extension point for augmenting the executorService of {@link SynchronousNonBlockingStepExecution}.
* Extension point for augmenting the executorService of {@link SynchronousNonBlockingStepExecution} and {@link GeneralNonBlockingStepExecution}.

Copy link
Author

Choose a reason for hiding this comment

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

Please see d44f505

*/
@Restricted(Beta.class)
public interface ExecutorServiceAugmentor extends ExtensionPoint {
/**
* Augment the executor service used by {@link SynchronousNonBlockingStepExecution} and {@link GeneralNonBlockingStepExecution}.
* @param executorService the executor service to augment
*/
ExecutorService augment(ExecutorService executorService);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jenkinsci.plugins.workflow.steps;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;

import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;

public class SynchronousNonBlockingStepExecutorServiceAugmentorTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Rule
public LoggerRule loggerRule =
new LoggerRule().record(AugmentorTestExtension.class, Level.FINE).capture(10);

@Test
public void smokes() throws Exception {
SynchronousNonBlockingStepExecution.getExecutorService();
assertThat(loggerRule.getMessages(), hasItem("Augmenting"));
}

@TestExtension
public static class AugmentorTestExtension
implements SynchronousNonBlockingStepExecution.ExecutorServiceAugmentor {

private static final Logger LOGGER = Logger.getLogger(AugmentorTestExtension.class.getName());

@Override
public ExecutorService augment(ExecutorService executorService) {
LOGGER.fine(() -> "Augmenting");
return executorService;
}
}
}