-
Notifications
You must be signed in to change notification settings - Fork 105
Initial rough framework for plugins #952
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: main
Are you sure you want to change the base?
Changes from 1 commit
defe0bb
66b031c
381e0cc
0db686d
6bcd2fd
b5db959
759e650
e1dfe5c
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 |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
import asyncio | ||
import concurrent.futures | ||
import sys | ||
import uuid | ||
from datetime import timedelta | ||
from typing import Any, Awaitable, Callable, Optional, Sequence | ||
from urllib.request import urlopen | ||
|
||
import temporalio.api.enums.v1 | ||
import temporalio.client | ||
import temporalio.worker._worker | ||
from temporalio import activity, workflow | ||
from temporalio.api.workflowservice.v1 import ( | ||
|
@@ -19,7 +19,11 @@ | |
SetWorkerDeploymentRampingVersionRequest, | ||
SetWorkerDeploymentRampingVersionResponse, | ||
) | ||
from temporalio.client import BuildIdOpAddNewDefault, Client, TaskReachabilityType | ||
from temporalio.client import ( | ||
BuildIdOpAddNewDefault, | ||
Client, | ||
TaskReachabilityType, | ||
) | ||
from temporalio.common import PinnedVersioningOverride, RawValue, VersioningBehavior | ||
from temporalio.runtime import PrometheusConfig, Runtime, TelemetryConfig | ||
from temporalio.service import RPCError | ||
|
@@ -38,6 +42,7 @@ | |
SlotReleaseContext, | ||
SlotReserveContext, | ||
Worker, | ||
WorkerConfig, | ||
WorkerDeploymentConfig, | ||
WorkerDeploymentVersion, | ||
WorkerTuner, | ||
|
@@ -1184,3 +1189,46 @@ def shutdown(self) -> None: | |
if self.next_exception_task: | ||
self.next_exception_task.cancel() | ||
setattr(self.worker._bridge_worker, self.attr, self.orig_poll_call) | ||
|
||
|
||
class MyCombinedPlugin(temporalio.client.Plugin, temporalio.worker.Plugin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the value to users of this multiple inheritance approach? It seems to be a discoverability loss--knowing you can add a second base class is not a leap I'd expect most people to make. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say a few things:
@cretz probably has thoughts here. Name/version aren't present, but easy to add a function(s) to the Plugin classes which has to be implemented. I'll bring this up to the team as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically what @tconley1428 said. The main benefit is separating what you're plugging into, same as interceptors (and has consistency with interceptors on this front for those familiar). But it's not a big deal, we can make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is redundantly shown by the names of the methods and the types of those methods, e.g.
The purpose of a plugin is different from an interceptor. The whole point of a plugin is to bring together disparate things (interceptors, activities, etc) under one roof. The two purposes of this are (a) to help users easily add and (b) to give a roadmap for framework integrators to know what they can/need to do to. It's counterproductive to try to separate them out at this layer.
👍, I would be in favor of
I'm not following the root reason here. |
||
def on_create_worker(self, config: WorkerConfig) -> WorkerConfig: | ||
print("Create worker combined plugin") | ||
config["task_queue"] = "combined" | ||
return super().on_create_worker(config) | ||
|
||
|
||
class MyWorkerPlugin(temporalio.worker.Plugin): | ||
def on_create_worker(self, config: WorkerConfig) -> WorkerConfig: | ||
print("Create worker worker plugin") | ||
config["task_queue"] = "replaced_queue" | ||
return super().on_create_worker(config) | ||
|
||
async def run_worker(self, worker: Worker) -> None: | ||
await super().run_worker(worker) | ||
|
||
|
||
async def test_worker_plugin(client: Client) -> None: | ||
worker = Worker( | ||
client, | ||
task_queue="queue", | ||
activities=[never_run_activity], | ||
plugins=[MyWorkerPlugin()], | ||
) | ||
assert worker.config().get("task_queue") == "replaced_queue" | ||
|
||
# Test client plugin propagation to worker plugins | ||
new_config = client.config() | ||
new_config["plugins"] = [MyCombinedPlugin()] | ||
client = Client(**new_config) | ||
worker = Worker(client, task_queue="queue", activities=[never_run_activity]) | ||
assert worker.config().get("task_queue") == "combined" | ||
|
||
# Test both. Client propagated plugins are called first, so the worker plugin overrides in this case | ||
worker = Worker( | ||
client, | ||
task_queue="queue", | ||
activities=[never_run_activity], | ||
plugins=[MyWorkerPlugin()], | ||
) | ||
assert worker.config().get("task_queue") == "replaced_queue" |
Uh oh!
There was an error while loading. Please reload this page.