Ejemplo n.º 1
0
async def entity_stan(event_loop, client_id):
    """Create a stan connection for each function.

    Uses environment variables for the cluster name.
    """
    nc = Nats()
    sc = Stan()

    await nc.connect(io_loop=event_loop)

    cluster_name = os.getenv('STAN_CLUSTER_NAME', 'test-cluster')

    if not cluster_name:
        raise ValueError('Missing env variable: STAN_CLUSTER_NAME')

    await sc.connect(cluster_name, client_id, nats=nc)

    yield sc

    await sc.close()
    await nc.close()
Ejemplo n.º 2
0
async def entity_stan(app, event_loop, client_id):
    """Create a stan connection for each function.

    Uses environment variables for the cluster name.
    """
    nc = Nats()
    sc = Stan()

    await nc.connect(io_loop=event_loop)

    cluster_name = app.config['NATS_CLUSTER_ID']

    if not cluster_name:
        raise ValueError('Missing env variable: NATS_CLUSTER_ID')

    await sc.connect(cluster_name, client_id, nats=nc)

    yield sc

    await sc.close()
    await nc.close()
Ejemplo n.º 3
0
import traceback
import uuid

from nats.aio.client import Client as Nats

from kronk.config import Config
from kronk.database import Rethink
from kronk.kubernetes import GracefulTermination
from kronk.task import State
from kronk.task import Task

log = logging.getLogger(__name__)

config = Config()
graceful = GracefulTermination()
nc = Nats()
rdb = Rethink()


class Worker:
    def simulation(self) -> (int, str):
        """ Create a random execution time for a simulated job """

        task_shor = [1] * 60  # 60% chance of a job taking a short time
        task_medi = [2] * 30  # 30% chance of a job taking a medium time
        task_long = [3] * 10  # 10% chance of a job taking a long time
        task_fail = [
            "ready"
        ] * 50  # 50% chance of a job failing, set ready state to retry the job
        task_comp = ["complete"] * 50  # 50% chance of a job completing