属性#

State#

class takler.core.State(node_status=None)#

The state of a Node, include node status and other attributes.

node_status#

status of a node.

Type:

NodeStatus

suspended#

whether node is suspended from resolving.

Type:

bool

class takler.core.NodeStatus(*values)#

The running status of a node.

The status of a family is the largest status of all children nodes' status.

Current type of status:

  • unknown: if flow is not begin, all nodes is in unknown

  • complete: task is finished

  • queued: task is waiting for its dependencies to be satisfied.

  • submitted: task is submitted to its runner, but not running.

  • active: task is running.

  • aborted: task exists with some error.

Parameter#

class takler.core.Parameter(name, value=None)#
classmethod from_dict(d, method=SerializationType.Status)#
参数:
  • d (Dict) --

    {
        "name": parameter name,
        "value": parameter value, str or int or float or boolean
    }
    

  • method (SerializationType) --

    • SerializationType.Status

    • SerializationType.Tree

返回类型:

Parameter

to_dict()#
返回:

{
    "name": parameter name,
    "value": parameter value, str or int or float or boolean
}

返回类型:

Dict

Time#

class takler.core.TimeAttribute(time)#

Time dependency for a Node.

Node should only be run until time dependency is satisfied.

time#

time point when the node should begin to run.

free#

if marked true, time attributes is ignored.

calendar_changed(calendar)#

When calendar equals TimeAttribute's time, the TimeAttribute is satisfied. After this time, TimeAttribute should always be satisfied until Node is requeue. So when calendar changed, TimeAttributes should be checked. If it is satisfied, it should be marked free to prevent future time check.

参数:

calendar (Calendar) -- The calendar of a Flow

clear_free()#

Clear TimeAttribute's free flag.

is_free(calendar)#

Check whether TimeAttribute is satisfied.

Time attribute is satisfied when:

  1. Flow calendar's time (HH:MM) is equal to time attribute's time (HH:MM).

  2. Or free flag is marked.

参数:

calendar (Calendar)

返回类型:

bool

reset()#

Clear free flag

set_free()#

Mark TimeAttribute's free flag.

Trigger#

class takler.core.expression.Expression(expression_str)#

An expression for trigger in nodes.

free#

expression with free set is always True.

ast#

expression AST parsed from expression string.

expression_str#

original expression string.

create_ast(parent_node)#

Create AST from expression string and set parent node for the AST.

evaluate()#

Calculate the expression result. If free flag is set, always return True.

返回类型:

bool

parse_expression()#

Parse expression string and create an AST.

Limit#

class takler.core.Limit(name, limit)#

Limit is used to control task running, and it is an attribution attached to some Node. The number of running Tasks with some Limit should not be large than Limit's limit.

name#

Limit's name. Limits in one Node should have different names.

limit#

total number of tokens.

value#

current occupied tokens.

node#

node who holds the Limit.

node_paths#

list of node path that is occupying the Limit.

decrement(tokens, node_path)#

Release tokens for some node by decrement Limit value.

参数:
  • tokens (int) -- number of tokens for node, usually is 1.

  • node_path (str) -- full node path. See Node.node_path

in_limit(tokens)#

check if there has enough tokens.

返回类型:

bool

increment(tokens, node_path)#

Occupy tokens for some node by increment Limit value.

参数:
  • tokens (int) -- number of tokens for node, usually is 1.

  • node_path (str) -- full node path. See Node.node_path

reset()#

reset the limit. Clear node path list and set current value to 0.

set_node(node)#

set reference node for Limit.

class takler.core.limit.InLimit(limit_name, node_path=None, tokens=1)#

An attribution of Node to mark current Node and all its children to use some Limit. One Node could have multiply InLimit is managed by InLimitManager.

limit_name#

name of the Limit.

tokens#

number of tokens for one node. Default is 1.

node_path#

reference node of the Limit. If None, InLimitManager will search up the node tree.

limit#

the Limit object

class takler.core.limit.InLimitManager(node)#

Manager Node. Deal with Limit increment and decrement.

node#

reference node who has the InLimitManager

Type:

Node

in_limit_list#

list of InLimit

Type:

List[InLimit]

Repeat#

class takler.core.Repeat(r=None)#

An attribute for Node to run tasks repeatedly under this Node.

r#

inner RepeatBase object. If None, empty returns False.

change(value)#

Change Repeat current value and will raise exception if value is not valid.

clear()#

Clear Repeat and make it empty.

empty()#

Check if Repeat is empty.

返回类型:

bool

end()#

Return the last (end) value.

返回类型:

TypeVar(T)

generated_parameters()#

Return generated parameters.

返回类型:

Dict[str, Parameter]

increment()#

Increment Repeat to next value, return True if successful.

返回类型:

bool

reset()#

Reset Repeat to the first value.

set_value(value)#

Set Repeat current value without raising exception.

start()#

Return the first (start) value.

返回类型:

TypeVar(T)

step()#

Return step.

valid()#

Check if current value if valid.

返回类型:

bool

value()#

Return current value.

返回类型:

TypeVar(T)

Event#

class takler.core.Event(name, initial_value=False)#

Event is an attribute for Task node to set some flag while task is running.

name#

Event's name

Type:

str

initial_value#

initial value of Event, default is False

Type:

bool

_value#

current value of Event

Type:

bool

classmethod from_dict(d, method=SerializationType.Status)#

Create an Event from dict object.

If method is Status, set Event's value to d["value"].

If method is Tree, only set initial value.

参数:
  • d (Dict) -- dict object for an Event

  • method (SerializationType) -- serialization type.

返回类型:

Event

示例

>>> d = {'name': 'event1', 'initial_value': False, 'value': True}
>>> Event.from_dict(d, method=SerializationType.Status)
Event(event1, set)
>>> Event.from_dict(d, method=SerializationType.Tree)
Event(event1, unset)

If Tree method is used, value key is not neccessary.

>>> d = {'name': 'event1', 'initial_value': False}
>>> Event.from_dict(d, method=SerializationType.Tree)
Event(event1, unset)
reset()#

Set Event to its initial value, which is typically False.

to_dict()#

Convert Event to dict object. For Example:

{
    "name": "event1",
    "initial_value": False,
    "value": True
}
返回:

dict form of Event.

返回类型:

Dict

示例

>>> event = Event("event1")
>>> event.to_dict()
{'name': 'event1', 'initial_value': False, 'value': False}
>>> event.value = True
>>> event.to_dict()
{'name': 'event1', 'initial_value': False, 'value': True}
property value: bool#

current value of Event.

Type:

str

Meter#

class takler.core.Meter(name, min_value, max_value)#

An integer attribute with value range.

name#

meter name

Type:

str

min_value#

min value, meter's initial value is min value

Type:

int

max_value#

max value

Type:

int

_value#

current value

Type:

int

classmethod from_dict(d, method=SerializationType.Status)#

Create a Meter from dict object.

If method is Status, set Meter's value to d["value"].

If method is Tree, only set min and max value.

参数:
  • d (Dict) -- dict object for a Meter

  • method (SerializationType) -- serialization type.

返回类型:

Meter

示例

>>> d = {'name': 'meter1', 'min_value': 0, 'max_value': 100, 'value': 10}
>>> Meter.from_dict(d, method=SerializationType.Status)
Meter(meter1, [0, 100], 10)
>>> Meter.from_dict(d, method=SerializationType.Tree)
Meter(meter1, [0, 100], 0)

If Tree method is used, value key is not neccessary.

>>> d = {'name': 'meter1', 'min_value': 0, 'max_value': 100}
>>> Meter.from_dict(d, method=SerializationType.Tree)
Meter(meter1, [0, 100], 0)
is_invalid(value)#

Check whether some value is in the range.

参数:

value (int) -- some value to be checked

返回类型:

bool

reset()#

set meter to its initial value, which is the min value.

to_dict()#

Convert Meter to dict object. For example:

{
    "name": "meter1",
    "min_value": 0,
    "max_value": 100,
    "value": 10
}
返回:

dict form of Meter

返回类型:

Dict

示例

>>> meter = Meter("meter1", 0, 100)
>>> meter.to_dict()
{'name': 'meter1', 'min_value': 0, 'max_value': 100, 'value': 0}
>>> meter.value = 10
>>> meter.to_dict()
{'name': 'meter1', 'min_value': 0, 'max_value': 100, 'value': 10}
property value: int#

current value of meter

Type:

int