Skip to content
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

fix: edit the job context and batch doc comments #148

Merged
merged 1 commit into from
Oct 16, 2024
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
12 changes: 6 additions & 6 deletions nitric/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ async def chained_middleware(ctx: C, nxt: Optional[Middleware[C]] = None) -> C:


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

data: dict[str, Any]

Expand All @@ -379,28 +379,28 @@ def __init__(self, data: dict[str, Any]):


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

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."""
"""Represents the full request/response context for a Job task trigger."""

def __init__(self, request: JobRequest, response: Optional[JobResponse] = None):
"""Construct a new EventContext."""
"""Construct a new JobContext."""
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."""
"""Construct a new JobContext from a Job trigger from the Nitric Server."""
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."""
"""Construct a JobContext for the Nitric Server from this context object."""
return BatchClientMessage(job_response=BatchJobResponse(success=self.res.success))


Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
memory: int | None = None,
gpus: int | None = None,
):
"""Construct a new WebsocketHandler."""
"""Construct a new JobHandler."""
self._handler = handler
self._responses = AsyncNotifierList()
self._registration_request = RegistrationRequest(
Expand All @@ -70,7 +70,7 @@ async def _message_request_iterator(self):
yield response

async def start(self) -> None:
"""Register this subscriber and listen for messages."""
"""Register this job handler and listen for tasks."""
channel = ChannelManager.get_channel()
server = JobStub(channel=channel)

Expand Down
Loading