Sequence(Token(segments=1, nonempty=True), unique=True), 'required': Boolean(default=True), }, nonnull=True), nonnull=True), 'startup_attempts': Integer(default=12), 'startup_enabled': Boolean(default=True), 'startup_timeout': Integer(default=5), }, name='parameters') log = LogHelper('spire.runtime') class Runtime(object): """A spire runtime.""" guard = Lock() runtime = None def __new__(cls, *args, **params): with Runtime.guard: Runtime.runtime = super(Runtime, cls).__new__(cls, *args, **params) return Runtime.runtime def __init__(self, configuration=None, assembly=None): self.assembly = assembly or Assembly.current()
from datetime import datetime, timedelta from scheme import UTC, current_timestamp from spire.schema import * from spire.support.logs import LogHelper from sqlalchemy.sql import bindparam, text from platoon.models.subscribedtask import SubscribedTask __all__ = ('Event', ) log = LogHelper('platoon') schema = Schema('platoon') class Event(Model): """An event.""" class meta: schema = schema tablename = 'event' id = Identifier() topic = Token(nullable=False) aspects = Hstore() status = Enumeration('pending completed', nullable=False, default='pending') occurrence = DateTime(timezone=True) HSTORE_FILTER = text(':aspects @> subscribed_task.aspects', bindparams=[bindparam('aspects', type_=aspects.type)])
from mesh.standard import bind from spire.mesh import MeshDependency, ModelController, support_returning from spire.schema import * from spire.support.logs import LogHelper from flux.bindings import platoon from flux.models import Message, Request from flux.operations import * from flux.resources.request import Request as RequestResource ScheduledTask = bind(platoon, 'platoon/1.0/scheduledtask') Event = bind(platoon, 'platoon/1.0/event') log = LogHelper('flux') class RequestController(ModelController): resource = RequestResource version = (1, 0) model = Request mapping = ( 'id name status originator assignee creator ' 'slot_order claimed completed' ) schema = SchemaDependency('flux') docket_entity = MeshDependency('docket.entity') flux = MeshDependency('flux') platoon = MeshDependency('platoon') @support_returning def create(self, request, response, subject, data):
import time from scheme import Sequence, Token from spire.core import Configuration, Dependency, Unit from spire.mesh import MeshDependency from spire.runtime import current_runtime from spire.schema import SchemaDependency from spire.support.logs import LogHelper from spire.support.threadpool import ThreadPool from spire.util import topological_sort from nucleus.models import * log = LogHelper('nucleus') class InvalidDependencyError(Exception): """...""" TIMEOUTS = [(10, 1), (20, 3), (30, 10), (40, 20)] def next_timeout(attempt): for threshold, timeout in TIMEOUTS: if attempt <= threshold: return timeout class ServiceRegistry(Unit): """The service registry."""
from mesh.standard import Controller, Resource, bind from mesh.standard.requests import add_schema_field from spire.core import Unit from spire.mesh import MeshDependency from spire.runtime import current_runtime from spire.schema import * from spire.schema.construction import FieldConstructor from spire.support.logs import LogHelper from spire.util import import_object, safe_table_name from sqlalchemy import MetaData from docket import resources from docket.bindings import platoon from docket.models import * log = LogHelper('docket') PROTOTYPES = (Concept, DocumentType) class ArchetypeRegistry(Unit): """The archetype registry.""" schema = SchemaDependency('docket') def __init__(self): self.models = {} def bootstrap(self): session = self.schema.session for prototype in PROTOTYPES:
from scheme import Boolean, Sequence, Text from werkzeug.exceptions import HTTPException, InternalServerError, NotFound from werkzeug.wrappers import Request, Response from spire.core import Configuration, Unit from spire.local import ContextLocals from spire.support.logs import LogHelper log = LogHelper('spire.wsgi') class Mount(Unit): configuration = Configuration({ 'middleware': Sequence(Text(nonempty=True), unique=True), 'path': Text(description='url path', nonempty=True), 'shared_path': Text(description='path segment shared with mount'), }) def __init__(self): try: self.application except AttributeError: self.application = self.dispatch middleware = self.configuration.get('middleware') if middleware: for attr in reversed(middleware): self.application = getattr(self, attr).wrap(self.application)
import errno import os import select import threading import time from scheme import Integer, Text from spire.core import Configuration, Unit, configured_property from spire.support.logs import LogHelper log = LogHelper(__name__) try: from os import mkfifo except ImportError: class Idler(Unit): configuration = Configuration({ 'timeout': Integer(default=30), }) timeout = configured_property('timeout') def idle(self, timeout=None): time.sleep(timeout or self.timeout) def interrupt(self): pass else:
from copy import deepcopy from spire.core.assembly import Assembly from spire.core.configuration import Configuration from spire.core.dependency import Dependency from spire.core.registry import Configurable, Registry from spire.exceptions import * from spire.support.logs import LogHelper from spire.util import get_constructor_args, identify_object __all__ = ('Component', 'ConfigurableUnit', 'Unit') log = LogHelper('spire.core') class UnitMeta(type): def __new__(metatype, name, bases, namespace): secondary = None for base in reversed(bases): metaclass = getattr(base, '__metaclass__', None) if metaclass and metaclass is not metatype: if not secondary: secondary = metaclass elif metaclass is not secondary: raise SpireError( 'cannot reconcile more then two metaclass bases') unit = None if secondary: metatype = type('metaclass', (metatype, secondary), {'__secondary_metaclass__': secondary})