-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add async job event bus publisher #12971
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
base: 4.22
Are you sure you want to change the base?
Changes from all commits
68c69df
26e5d3c
8f996ac
97b15fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, | |
| private volatile long _executionRunNumber = 1; | ||
|
|
||
| private final ScheduledExecutorService _heartbeatScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AsyncJobMgr-Heartbeat")); | ||
| private final ExecutorService _eventBusPublisher = Executors.newSingleThreadExecutor(new NamedThreadFactory("AsyncJobMgr-EventBus")); | ||
| private ExecutorService _apiJobExecutor; | ||
| private ExecutorService _workerJobExecutor; | ||
|
|
||
|
|
@@ -1378,6 +1379,7 @@ public boolean start() { | |
| @Override | ||
| public boolean stop() { | ||
| _heartbeatScheduler.shutdown(); | ||
| _eventBusPublisher.shutdown(); | ||
| _apiJobExecutor.shutdown(); | ||
| _workerJobExecutor.shutdown(); | ||
|
Comment on lines
1379
to
1384
|
||
| return true; | ||
|
|
@@ -1397,8 +1399,22 @@ protected AsyncJobManagerImpl() { | |
| } | ||
|
|
||
| private void publishOnEventBus(AsyncJob job, String jobEvent) { | ||
| _messageBus.publish(null, AsyncJob.Topics.JOB_EVENT_PUBLISH, PublishScope.LOCAL, | ||
| new Pair<AsyncJob, String>(job, jobEvent)); | ||
| try { | ||
| _eventBusPublisher.submit(new ManagedContextRunnable() { | ||
| @Override | ||
| protected void runInContext() { | ||
| try { | ||
| _messageBus.publish(null, AsyncJob.Topics.JOB_EVENT_PUBLISH, PublishScope.LOCAL, | ||
| new Pair<>(job, jobEvent)); | ||
| } catch (Throwable t) { | ||
| logger.warn("Failed to publish async job event on message bus. jobId={}, jobEvent={}", | ||
| job != null ? job.getId() : null, jobEvent, t); | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
1401
to
+1414
|
||
| } catch (RejectedExecutionException e) { | ||
| logger.warn("Failed to publish async job event, event bus publisher is shut down", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Executors.newSingleThreadExecutor(...)uses an unbounded LinkedBlockingQueue. If_messageBus.publish()blocks (the original issue) for extended periods, this queue can grow without bound and increase memory pressure or OOM under sustained load. Consider using a boundedThreadPoolExecutor(still single-threaded) with an explicit queue size and a rejection policy (e.g., log+drop or CallerRuns as a backpressure mechanism) that matches desired guarantees for job event delivery.