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
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test:
@echo Running Tox tests
@tox -e py

NITRIC_VERSION := 1.6.0
NITRIC_VERSION := 1.14.0

download-local:
@rm -r ./proto/nitric
Expand Down
2 changes: 2 additions & 0 deletions nitric/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Nitric:
"keyvaluestore": {},
"oidcsecuritydefinition": {},
"sql": {},
"job": {},
"jobdefinition": {},
}

@classmethod
Expand Down
41 changes: 41 additions & 0 deletions nitric/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
from nitric.proto.topics.v1 import ClientMessage as TopicClientMessage
from nitric.proto.topics.v1 import MessageResponse as TopicResponse
from nitric.proto.topics.v1 import ServerMessage as TopicServerMessage
from nitric.proto.batch.v1 import (
ServerMessage as BatchServerMessage,
ClientMessage as BatchClientMessage,
JobResponse as BatchJobResponse,
)
from nitric.utils import dict_from_struct

Record = Dict[str, Union[str, List[str]]]
Expand Down Expand Up @@ -363,6 +368,42 @@ async def chained_middleware(ctx: C, nxt: Optional[Middleware[C]] = None) -> C:
return composed


class JobRequest:
"""Represents a translated Job, from a Job Definition, forwarded from the Nitric Runtime Server."""

data: dict[str, Any]

def __init__(self, data: dict[str, Any]):
"""Construct a new JobRequest."""
self.data = data


class JobResponse:
"""Represents the response to a trigger from a Job submission as a result of a SubmitJob call."""

def __init__(self, success: bool = True):
"""Construct a new EventResponse."""
self.success = success


class JobContext:
"""Represents the full request/response context for an Event based trigger."""

def __init__(self, request: JobRequest, response: Optional[JobResponse] = None):
"""Construct a new EventContext."""
self.req = request
self.res = response if response else JobResponse()

@staticmethod
def _from_request(msg: BatchServerMessage) -> "JobContext":
"""Construct a new EventContext from a Topic trigger from the Nitric Membrane."""
return JobContext(request=JobRequest(data=dict_from_struct(msg.job_request.data.struct)))

def to_response(self) -> BatchClientMessage:
"""Construct a EventContext for the Nitric Membrane from this context object."""
return BatchClientMessage(job_response=BatchJobResponse(success=self.res.success))


class FunctionServer(ABC):
"""Represents a worker that should be started at runtime."""

Expand Down
Empty file added nitric/proto/batch/__init__.py
Empty file.
211 changes: 211 additions & 0 deletions nitric/proto/batch/v1/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions nitric/proto/deployments/v1/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions nitric/proto/resources/v1/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions nitric/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from nitric.resources.websockets import Websocket, websocket
from nitric.resources.queues import Queue, queue
from nitric.resources.sql import Sql, sql
from nitric.resources.job import job, Job

__all__ = [
"api",
Expand All @@ -38,6 +39,8 @@
"Bucket",
"kv",
"KeyValueStoreRef",
"job",
"Job",
"oidc_rule",
"queue",
"Queue",
Expand Down
Loading