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
6 changes: 2 additions & 4 deletions oocana/oocana/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
from .throttler import throttle
from .preview import PreviewPayload, DataFrame, PreviewPayloadInternal, ShapeDataFrame
from .data import EXECUTOR_NAME
from .internal import random_string, InternalAPI
import os.path
import logging
import random
import string
import hashlib

__all__ = ["Context", "HandleDefDict", "BlockJob", "BlockExecuteException"]

def random_string(length=8):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))

def string_hash(text: str) -> str:
"""
Expand Down Expand Up @@ -194,6 +191,7 @@ def __init__(
) -> None:

self.__block_info = blockInfo
self.internal: InternalAPI = InternalAPI(mainframe, blockInfo.job_info())

self.__mainframe = mainframe
self.__store = store
Expand Down
32 changes: 32 additions & 0 deletions oocana/oocana/internal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from .mainframe import Mainframe
from .data import JobDict
import random
import string
import math

class InternalAPI:

def __init__(self, client: Mainframe, job_id: JobDict) -> None:
self._client = client
self._job_id = job_id

# keep this method async for future use
async def update_node_weight(self, node_id: str, weight: int | float) -> None:
"""
Update the weight of a node.
:param node_id: The ID of the node to update.
:param weight: The new weight for the node.
"""
if not isinstance(weight, (int, float)) or not math.isfinite(weight) or weight < 0:
raise ValueError("Weight must be a non-negative finite number.")

self._client.send(self._job_id, {
"type": "BlockRequest",
"action": "UpdateNodeWeight",
"node_id": node_id,
"weight": weight,
"request_id": random_string(16),
})

def random_string(length=8):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))