Skip to content
Merged
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
1 change: 1 addition & 0 deletions impl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ This SDK is modular by design—pull in only what you need:
* **serverlessworkflow-impl-function** Function support.
* **serverlessworkflow-impl-template-resolver** JaxRS URI template implementation.
* **serverlessworkflow-impl-json** Json common utilities shared by all modules in this list
* **serverlessworkflow-impl-cron** Cron parsing

* **serverlessworkflow-impl-http**
HTTP `Call` task handler, based on Jax-RS client
Expand Down
4 changes: 0 additions & 4 deletions impl/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
import io.serverlessworkflow.impl.resources.ResourceLoaderFactory;
import io.serverlessworkflow.impl.resources.URITemplateResolver;
import io.serverlessworkflow.impl.scheduler.AllStrategyCorrelationInfoFactory;
import io.serverlessworkflow.impl.scheduler.CronResolver;
import io.serverlessworkflow.impl.scheduler.CronResolverFactory;
import io.serverlessworkflow.impl.scheduler.DefaultWorkflowScheduler;
import io.serverlessworkflow.impl.scheduler.InMemoryAllStrategyCorrelationInfo;
import io.serverlessworkflow.impl.scheduler.WorkflowScheduler;
import io.serverlessworkflow.impl.schema.SchemaValidator;
import io.serverlessworkflow.impl.schema.SchemaValidatorFactory;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -68,6 +71,8 @@
import java.util.ServiceLoader.Provider;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -104,6 +109,7 @@ public class WorkflowApplication implements AutoCloseable {
private final CloudEventPredicateFactory cloudEventPredicateFactory;
private final AllStrategyCorrelationInfoFactory allStrategyCorrelationInfoFactory;
private final WorkflowLifeCycleCloudEventFactory lifeCycleCloudEventFactory;
private final ScheduledExecutorService schedulerExecutorService;

private WorkflowApplication(Builder builder) {
this.taskFactory = builder.taskFactory;
Expand Down Expand Up @@ -137,6 +143,7 @@ private WorkflowApplication(Builder builder) {
this.cloudEventPredicateFactory = builder.cloudEventPredicateFactory;
this.allStrategyCorrelationInfoFactory = builder.allStrategyCorrelationInfoFactory;
this.lifeCycleCloudEventFactory = builder.lifeCycleCloudEventFactory;
this.schedulerExecutorService = builder.schedulerExecutorService;
}

public TaskExecutorFactory taskFactory() {
Expand Down Expand Up @@ -259,6 +266,8 @@ public SchemaValidator getValidator(SchemaInline inline) {
private CloudEventPredicateFactory cloudEventPredicateFactory;
private AllStrategyCorrelationInfoFactory allStrategyCorrelationInfoFactory;
private WorkflowLifeCycleCloudEventFactory lifeCycleCloudEventFactory;
private CronResolverFactory cronResolverFactory;
private ScheduledExecutorService schedulerExecutorService;

private Builder() {
ServiceLoader.load(NamedWorkflowAdditionalObject.class)
Expand Down Expand Up @@ -413,6 +422,11 @@ public Builder withLifeCycleCloudEventFactory(
return this;
}

public Builder withCronResolverFactory(CronResolverFactory cronResolverFactory) {
this.cronResolverFactory = cronResolverFactory;
return this;
}

public WorkflowApplication build() {

if (modelFactory == null) {
Expand Down Expand Up @@ -452,8 +466,31 @@ public WorkflowApplication build() {
if (idFactory == null) {
idFactory = new MonotonicUlidWorkflowInstanceIdFactory();
}

if (scheduler == null) {
scheduler = new DefaultWorkflowScheduler();
if (cronResolverFactory == null) {
cronResolverFactory =
loadFirst(CronResolverFactory.class)
.orElseGet(
() ->
new CronResolverFactory() {
private CronResolver emptyResolver =
new CronResolver() {
@Override
public Optional<Duration> nextExecution() {
throw new UnsupportedOperationException(
"Missing CronResolverFactory, please add serverlessworkflow-impl-cron dependency to your classpath");
}
};

@Override
public CronResolver parseCron(String cron) {
return emptyResolver;
}
});
Comment on lines +476 to +490
}
schedulerExecutorService = Executors.newSingleThreadScheduledExecutor();
scheduler = new DefaultWorkflowScheduler(schedulerExecutorService, cronResolverFactory);
}
schedulerListener = new SchedulerListener(scheduler);
listeners.add(schedulerListener);
Expand Down Expand Up @@ -532,6 +569,9 @@ public void close() {
}
listenersByPriority.clear();
}
if (this.schedulerExecutorService != null) {
schedulerExecutorService.shutdownNow();
}
}

public WorkflowPositionFactory positionFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.serverlessworkflow.impl.scheduler;

public interface CronResolverFactory {
import io.serverlessworkflow.impl.ServicePriority;

public interface CronResolverFactory extends ServicePriority {
CronResolver parseCron(String cron);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.serverlessworkflow.impl.WorkflowDefinition;
import io.serverlessworkflow.impl.WorkflowInstance;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand All @@ -28,10 +27,6 @@ public class DefaultWorkflowScheduler extends ExecutorServiceWorkflowScheduler {

private final CronResolverFactory cronFactory;

public DefaultWorkflowScheduler() {
this(Executors.newSingleThreadScheduledExecutor(), new CronUtilsResolverFactory());
}

public DefaultWorkflowScheduler(
ScheduledExecutorService service, CronResolverFactory cronFactory) {
super(service);
Expand Down
20 changes: 20 additions & 0 deletions impl/cron/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>
<artifactId>serverlessworkflow-impl-cron</artifactId>
<name>Serverless Workflow :: Impl :: Cron</name>
<dependencies>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.scheduler;
package io.serverlessworkflow.impl.cron;

import com.cronutils.model.Cron;
import com.cronutils.model.time.ExecutionTime;
import io.serverlessworkflow.impl.scheduler.CronResolver;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.scheduler;
package io.serverlessworkflow.impl.cron;

import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.parser.CronParser;
import io.serverlessworkflow.impl.scheduler.CronResolver;
import io.serverlessworkflow.impl.scheduler.CronResolverFactory;

class CronUtilsResolverFactory implements CronResolverFactory {
public class CronUtilsResolverFactory implements CronResolverFactory {

private final CronParser cronParser;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.serverlessworkflow.impl.cron.CronUtilsResolverFactory
4 changes: 4 additions & 0 deletions impl/jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-lifecycle-events</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-cron</artifactId>
</dependency>
</dependencies>
</project>
6 changes: 6 additions & 0 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
<artifactId>serverlessworkflow-impl-a2a</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-cron</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
Expand Down Expand Up @@ -231,5 +236,6 @@
<module>grpc</module>
<module>openapi-jackson</module>
<module>a2a</module>
<module>cron</module>
</modules>
</project>
4 changes: 4 additions & 0 deletions impl/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-cron</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
Expand Down
Loading