Skip to content

Commit

Permalink
Improve process program
Browse files Browse the repository at this point in the history
  • Loading branch information
slietar committed Jun 26, 2023
1 parent 4da61ed commit 7739810
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 117 deletions.
104 changes: 58 additions & 46 deletions client/src/process.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const computeGraph: ProtocolBlockGraphRenderer<ProtocolBlock, ProcessLocation<un
element: (
<GraphNode
activity={location
? [ProcessLocationMode.Broken, ProcessLocationMode.Paused].includes(location.mode)
? (location.mode.type !== 'running')
? 'paused'
: 'active'
: 'default'}
Expand Down Expand Up @@ -92,21 +92,21 @@ export interface ProcessBlock<Data> extends ProtocolBlock {

export interface ProcessLocation<Location> extends MasterBlockLocation {
children: {};
mode: ProcessLocationMode;
pausable: boolean;
process: Location | null;
time: number;
}

export enum ProcessLocationMode {
Broken = 0,
Halting = 1,
Normal = 2,
Pausing = 3,
Paused = 4,
ResumingProcess = 5,
Starting = 6,
Terminated = 7
date: number;
mode: {
type: 'collecting';
} | {
type: 'collectionFailed';
} | {
type: 'failed';
} | {
type: 'halting';
} | {
type: 'running';
pausable: boolean;
processLocation: Location | null;
form: 'halting' | 'jumping' | 'normal' | 'paused' | 'pausing';
};
}

export function createProcessBlockImpl<Data, Location>(options: {
Expand All @@ -115,65 +115,77 @@ export function createProcessBlockImpl<Data, Location>(options: {
data: Data;
date: number;
location: Location;
status: 'normal' | 'paused';
}>;
createFeatures?(data: Data, location: Location | null): FeatureDef[];
getLabel?(data: Data): string | null;
}): PluginBlockImpl<ProcessBlock<Data>, ProcessLocation<Location>> {
return {
Component(props) {
if (props.location.mode === ProcessLocationMode.Broken) {
let mode = props.location.mode;

// return <p>{JSON.stringify(mode)}</p>

if (mode.type === 'failed') {
return (
<p style={{ margin: '1rem 0' }}>An error occured.</p>
);
}

let Component = options.Component;

if (Component && props.location.process) {
if (Component && (mode.type === 'running') && mode.processLocation) {
return (
<Component
data={props.block.data}
date={props.location.time}
date={props.location.date}
context={props.context}
location={props.location.process} />
location={mode.processLocation}
status={(mode.form === 'paused') ? 'paused' : 'normal'} />
);
}

return null;
},
computeGraph,
createCommands(block, location, context) {
if (location.mode === ProcessLocationMode.Paused) {
return [{
id: 'resume',
label: 'Resume',
shortcut: 'P',
onTrigger() {
context.pool.add(async () => {
await context.sendMessage({ type: 'resume' });
});
}
}];
}

if (location.pausable) {
return [{
id: 'pause',
disabled: (location.mode !== ProcessLocationMode.Normal),
label: 'Pause',
shortcut: 'P',
onTrigger() {
context.pool.add(async () => {
await context.sendMessage({ type: 'pause' });
});
}
}];
if (location.mode.type === 'running') {
if (location.mode.form === 'paused') {
return [{
id: 'resume',
label: 'Resume',
shortcut: 'P',
onTrigger() {
context.pool.add(async () => {
await context.sendMessage({ type: 'resume' });
});
}
}];
}

if (location.mode.pausable) {
return [{
id: 'pause',
disabled: (location.mode.form !== 'normal'),
label: 'Pause',
shortcut: 'P',
onTrigger() {
context.pool.add(async () => {
await context.sendMessage({ type: 'pause' });
});
}
}];
}
}

return [];
},
createFeatures(block, location) {
return options.createFeatures?.(block.data, location?.process ?? null) ?? [
let processLocation = (location?.mode.type === 'running')
? location.mode.processLocation
: null;

return options.createFeatures?.(block.data, processLocation) ?? [
{ icon: 'not_listed_location',
label: 'Process' }
];
Expand Down
6 changes: 4 additions & 2 deletions host/pr1/fiber/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from ..units.base import BaseRunner
from .master2 import Mark, ProgramHandle
from .process import BaseProcess
from ..procedure import BaseClassProcess



class DuplicateLeadTransformInLayerError(Diagnostic):
Expand Down Expand Up @@ -325,7 +327,7 @@ def adopt(self, data: Any, /, adoption_stack: EvalStack, trace: Trace) -> tuple[

@final
class ProcessTransformer(BaseLeadTransformer):
def __init__(self, Process: 'type[BaseProcess]', attributes: dict[str, lang.Attribute], *, parser: 'FiberParser'):
def __init__(self, Process: 'BaseClassProcess', attributes: dict[str, lang.Attribute], *, parser: 'FiberParser'):
assert attributes and (len(attributes) == 1)

for attr in attributes.values():
Expand All @@ -345,7 +347,7 @@ def prepare(self, data: dict[LocatedString, LocatedValue], /, envs):
return LanguageServiceAnalysis(), list()

def adopt(self, data: Evaluable, /, adoption_stack, trace):
from .process import ProcessBlock
from ..procedure import ProcessBlock

analysis = LanguageServiceAnalysis()
result = analysis.add(data.evaluate_provisional(EvalContext(adoption_stack)))
Expand Down
13 changes: 4 additions & 9 deletions host/pr1/fiber/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from types import EllipsisType
from typing import TYPE_CHECKING, Any, AsyncIterator, ClassVar, Generic, Optional, Self, TypeVar

from ..procedure import BaseClassProcess, ProcessProtocol
from ..eta import DatetimeTerm, DurationTerm

from ..error import Diagnostic
from ..reader import PossiblyLocatedValue
from .expr import Evaluable
Expand Down Expand Up @@ -55,18 +55,14 @@ class ProcessTerminationEvent(BaseProcessEvent):
ProcessEvent = ProcessExecEvent | ProcessFailureEvent | ProcessPauseEvent | ProcessTerminationEvent


class BaseProcessPoint(ABC):
pass


T_ProcessData = TypeVar('T_ProcessData')
S_ProcessPoint = TypeVar('S_ProcessPoint', bound=BaseProcessPoint)
S_ProcessPoint = TypeVar('S_ProcessPoint')

class BaseProcess(ABC, Generic[T_ProcessData, S_ProcessPoint]):
name: ClassVar[str]
namespace: ClassVar[str]

Point: ClassVar[Optional[type[BaseProcessPoint]]] = None
Point: ClassVar[Optional[type]] = None

def __init__(self, data: T_ProcessData, /, master: 'Master'):
...
Expand Down Expand Up @@ -101,7 +97,7 @@ def export_data(data: Any, /) -> Any:


class ProcessBlock(BaseBlock, Generic[T_ProcessData, S_ProcessPoint]):
def __init__(self, data: Evaluable[PossiblyLocatedValue[T_ProcessData]], ProcessType: type[BaseProcess[T_ProcessData, S_ProcessPoint]], /):
def __init__(self, data: Evaluable[PossiblyLocatedValue[T_ProcessData]], ProcessType: BaseClassProcess, /):
self._data = data
self._ProcessType = ProcessType

Expand Down Expand Up @@ -495,7 +491,6 @@ async def run(self, point, stack):
__all__ = [
'BaseProcess',
'BaseProcessEvent',
'BaseProcessPoint',
'ProcessError',
'ProcessExecEvent',
'ProcessFailureEvent',
Expand Down
Loading

0 comments on commit 7739810

Please sign in to comment.