Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Dec 11, 2024
1 parent f8f76b7 commit 0af7d99
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
10 changes: 8 additions & 2 deletions docs/guide/src/docs/asciidoc/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,16 @@ You can override the default scheduler (`TaskExecutors.SCHEDULED`) by setting th
[source,yaml]
.Setting the Default Scheduler
----
include::{root-dir}/libs/micronaut-worker/src/test/resources/application-virtual.yml[]
include::{root-dir}/libs/micronaut-worker/src/test/resources/application-scheduler.yml[]
----

TIP: You can let your jobs executed using virtual threads by using `virtual` executor.
You can use virtual thread factory with all the implicit executor services by setting the `worker.virtual-threads-compatible` property to `true`. Implicit executor services are created for every job that does not customize its own `scheudler` configuration property.

[source,yaml]
.Enabling Virtual Threads for Implicit Executors
----
include::{root-dir}/libs/micronaut-worker/src/test/resources/application-virtual-threads.yml[]
----

=== Job Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getScheduler() {
}

@Override
public boolean isVirtualThreadCompatible() {
public boolean isVirtualThreadsCompatible() {
return DEFAULT_VIRTUAL_THREAD_COMPATIBLE;
}

Expand All @@ -56,6 +56,6 @@ public boolean isVirtualThreadCompatible() {

String getScheduler();

boolean isVirtualThreadCompatible();
boolean isVirtualThreadsCompatible();

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class DefaultWorkerConfiguration implements WorkerConfiguration {

private boolean enabled;
private boolean virtualThreadsCompatible = WorkerConfiguration.DEFAULT_VIRTUAL_THREAD_COMPATIBLE;
private String queueType;
private String scheduler = WorkerConfiguration.DEFAULT_SCHEDULER;

Expand Down Expand Up @@ -62,4 +63,13 @@ public void setScheduler(String scheduler) {
this.scheduler = scheduler;
}

@Override
public boolean isVirtualThreadsCompatible() {
return virtualThreadsCompatible;
}

public void setVirtualThreadsCompatible(boolean virtualThreadsCompatible) {
this.virtualThreadsCompatible = virtualThreadsCompatible;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.agorapulse.worker.Job;
import com.agorapulse.worker.JobConfiguration;
import com.agorapulse.worker.WorkerConfiguration;
import io.micronaut.context.BeanContext;
import io.micronaut.context.Qualifier;
import io.micronaut.inject.qualifiers.Qualifiers;
Expand All @@ -41,9 +42,11 @@ public class DefaultExecutorServiceProvider implements ExecutorServiceProvider,
private final Map<String, ExecutorService> createdExecutors = new ConcurrentHashMap<>();

private final BeanContext beanContext;
private final WorkerConfiguration workerConfiguration;

public DefaultExecutorServiceProvider(BeanContext beanContext) {
public DefaultExecutorServiceProvider(BeanContext beanContext, WorkerConfiguration workerConfiguration) {
this.beanContext = beanContext;
this.workerConfiguration = workerConfiguration;
}

@Override
Expand All @@ -55,7 +58,7 @@ public void close() {

@Override
public ExecutorService getExecutorService(Job job) {
return getExecutor(ExecutorServiceProvider.getSchedulerName(job.getConfiguration()), job.getConfiguration().getFork(), job.getConfiguration().isVirtualThreadsCompatible());
return getExecutor(ExecutorServiceProvider.getSchedulerName(job.getConfiguration()), job.getConfiguration().getFork(), workerConfiguration.isVirtualThreadsCompatible() || job.getConfiguration().isVirtualThreadsCompatible());
}

@Override
Expand All @@ -73,7 +76,7 @@ public TaskScheduler getTaskScheduler(Job job) {
}

return optionalTaskScheduler.orElseGet(() -> {
ExecutorService executor = getExecutor(schedulerName, configuration.getFork(), configuration.isVirtualThreadsCompatible());
ExecutorService executor = getExecutor(schedulerName, configuration.getFork(), workerConfiguration.isVirtualThreadsCompatible() || configuration.isVirtualThreadsCompatible());
ScheduledExecutorTaskScheduler scheduler = new ScheduledExecutorTaskScheduler(executor);
beanContext.registerSingleton(TaskScheduler.class, scheduler, Qualifiers.byName(schedulerName));
return scheduler;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
worker:
scheduler: io
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
worker:
virtual-threads-compatible: true

This file was deleted.

0 comments on commit 0af7d99

Please sign in to comment.