mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-21 21:54:26 +00:00
Remove update_event as a single event loop for the system (#160)
This commit is contained in:
@ -36,6 +36,7 @@ from onefuzztypes.enums import (
|
||||
from onefuzztypes.models import Error
|
||||
from onefuzztypes.primitives import Container, PoolName, Region
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import Protocol
|
||||
|
||||
from .azure.table import get_client
|
||||
from .dashboard import add_event
|
||||
@ -66,6 +67,36 @@ KEY = Union[int, str, UUID, Enum]
|
||||
HOURS = 60 * 60
|
||||
|
||||
|
||||
class HasState(Protocol):
|
||||
# TODO: this should be bound tighter than Any
|
||||
# In the end, we want this to be an Enum. Specifically, one of
|
||||
# the JobState,TaskState,etc enums.
|
||||
state: Any
|
||||
|
||||
|
||||
def process_state_update(obj: HasState) -> None:
|
||||
"""
|
||||
process a single state update, if the obj
|
||||
implements a function for that state
|
||||
"""
|
||||
|
||||
func = getattr(obj, obj.state.name, None)
|
||||
if func is None:
|
||||
return
|
||||
func()
|
||||
|
||||
|
||||
def process_state_updates(obj: HasState, max_updates: int = 5) -> None:
|
||||
""" process through the state machine for an object """
|
||||
|
||||
for _ in range(max_updates):
|
||||
state = obj.state
|
||||
process_state_update(obj)
|
||||
new_state = obj.state
|
||||
if new_state == state:
|
||||
break
|
||||
|
||||
|
||||
def resolve(key: KEY) -> str:
|
||||
if isinstance(key, str):
|
||||
return key
|
||||
|
Reference in New Issue
Block a user