-
Notifications
You must be signed in to change notification settings - Fork 0
feat(java): handler registry, taskito-test, middleware contexts, submit payloads #308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f353dcd
feat(java): add HandlerRegistry and Worker.register
pratyush618 fd45041
feat(java): generate handlers() registry from @TaskHandler
pratyush618 593e9e4
test(java): cover register(handlers()) path
pratyush618 6891af5
feat(java): add taskito-test module with in-memory backend
pratyush618 58ce84f
test(java): cover in-memory worker execution and dead-lettering
pratyush618 ba85f09
feat(java): expose job metadata on the job view
pratyush618 c125954
feat(java): enrich middleware contexts (attributes, job metadata)
pratyush618 e84421d
test(java): cover middleware context enrichment
pratyush618 ab82917
feat(java): supply workflow payloads at submit time
pratyush618 a4f3b60
test(java): cover payloads-at-submit workflow
pratyush618 e41200a
docs(java): document payloads-at-submit workflows
pratyush618 62bef92
test(java): use generic List<Integer> task in fan-out test
pratyush618 14e8ebc
fix(java): fail fast on missing workflow submit payload
pratyush618 4ca0a7e
docs(java): point submitWorkflow javadoc at stepAfter
pratyush618 286cd20
fix(java): defensively copy HandlerRegistry varargs
pratyush618 817f3e9
fix(java): harden in-memory backend (atomic dedupe, cancel race, retr…
pratyush618 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| rootProject.name = "taskito" | ||
|
|
||
| include(":processor") | ||
| include(":test-support") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
sdks/java/src/main/java/org/byteveda/taskito/middleware/EnqueueContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sdks/java/src/main/java/org/byteveda/taskito/middleware/JobInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.byteveda.taskito.middleware; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * The executing job, exposed to {@link Middleware} hooks. {@link #metadata()} is | ||
| * loaded lazily (a storage read) only when first accessed, so middleware that | ||
| * never reads it pays nothing. | ||
| */ | ||
| public final class JobInfo { | ||
| private final String id; | ||
| private final String taskName; | ||
| private final Supplier<Map<String, Object>> metadataLoader; | ||
| private Map<String, Object> metadata; | ||
|
|
||
| public JobInfo(String id, String taskName, Supplier<Map<String, Object>> metadataLoader) { | ||
| this.id = id; | ||
| this.taskName = taskName; | ||
| this.metadataLoader = metadataLoader; | ||
| } | ||
|
|
||
| public String id() { | ||
| return id; | ||
| } | ||
|
|
||
| public String taskName() { | ||
| return taskName; | ||
| } | ||
|
|
||
| /** The job's metadata map (e.g. trace ids injected at enqueue); loaded on first call. */ | ||
| public Map<String, Object> metadata() { | ||
| if (metadata == null) { | ||
| metadata = metadataLoader.get(); | ||
| } | ||
| return metadata; | ||
| } | ||
| } |
29 changes: 27 additions & 2 deletions
29
sdks/java/src/main/java/org/byteveda/taskito/middleware/TaskContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,37 @@ | ||
| package org.byteveda.taskito.middleware; | ||
|
|
||
| /** Identifies a task as it executes on a worker. */ | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Identifies a task as it executes on a worker. {@link #attributes()} is a | ||
| * per-execution scratch map shared across {@code before}/{@code after}/ | ||
| * {@code onError} for the same job; {@link #job()} exposes its metadata. | ||
| */ | ||
| public final class TaskContext { | ||
| public final String jobId; | ||
| public final String taskName; | ||
|
|
||
| public TaskContext(String jobId, String taskName) { | ||
| private final Map<String, Object> attributes = new HashMap<>(); | ||
| private final JobInfo job; | ||
|
|
||
| public TaskContext(String jobId, String taskName, JobInfo job) { | ||
| this.jobId = jobId; | ||
| this.taskName = taskName; | ||
| this.job = job; | ||
| } | ||
|
|
||
| public TaskContext(String jobId, String taskName) { | ||
| this(jobId, taskName, new JobInfo(jobId, taskName, java.util.Collections::emptyMap)); | ||
| } | ||
|
|
||
| /** Mutable per-execution scratch shared across this job's middleware hooks. */ | ||
| public Map<String, Object> attributes() { | ||
| return attributes; | ||
| } | ||
|
|
||
| /** The executing job, including its (lazily loaded) metadata. */ | ||
| public JobInfo job() { | ||
| return job; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sdks/java/src/main/java/org/byteveda/taskito/worker/Handler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.byteveda.taskito.worker; | ||
|
|
||
| import org.byteveda.taskito.task.Task; | ||
| import org.byteveda.taskito.task.TaskFunction; | ||
|
|
||
| /** A task descriptor paired with the function that handles it. */ | ||
| public final class Handler<T, R> { | ||
| private final Task<T> task; | ||
| private final TaskFunction<T, R> function; | ||
|
|
||
| private Handler(Task<T> task, TaskFunction<T, R> function) { | ||
| this.task = task; | ||
| this.function = function; | ||
| } | ||
|
|
||
| public static <T, R> Handler<T, R> of(Task<T> task, TaskFunction<T, R> function) { | ||
| return new Handler<>(task, function); | ||
| } | ||
|
|
||
| public Task<T> task() { | ||
| return task; | ||
| } | ||
|
|
||
| public TaskFunction<T, R> function() { | ||
| return function; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
sdks/java/src/main/java/org/byteveda/taskito/worker/HandlerRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.byteveda.taskito.worker; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * An immutable bundle of {@link Handler}s registered together via | ||
| * {@code Worker.Builder.register}. Generated {@code <Class>Tasks.handlers(impl)} | ||
| * returns one of these. | ||
| */ | ||
| public final class HandlerRegistry { | ||
| private final List<Handler<?, ?>> handlers; | ||
|
|
||
| private HandlerRegistry(List<Handler<?, ?>> handlers) { | ||
| this.handlers = handlers; | ||
| } | ||
|
|
||
| public static HandlerRegistry of(Handler<?, ?>... handlers) { | ||
| // Copy the varargs array so later caller mutations can't leak in. | ||
| return new HandlerRegistry(Collections.unmodifiableList(new ArrayList<>(Arrays.asList(handlers)))); | ||
| } | ||
|
|
||
| public List<Handler<?, ?>> handlers() { | ||
| return handlers; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.