Example #1
0
def test_python():
    from packtivity.asyncbackends import ForegroundProxy

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p = load_proxy(p.json(),
                   {'proxy': 'py:packtivity.asyncbackends:ForegroundProxy'},
                   best_effort_backend=False)
    assert type(p) == ForegroundProxy
Example #2
0
def test_env(monkeypatch):
    from packtivity.asyncbackends import ForegroundProxy

    monkeypatch.setenv('PACKTIVITY_ASYNCBACKEND','packtivity.asyncbackends:ForegroundBackend:ForegroundProxy')

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p,_ = load_proxy(p.json())
    assert type(p) == ForegroundProxy
Example #3
0
def test_env(monkeypatch):
    from packtivity.asyncbackends import ForegroundProxy

    monkeypatch.setenv(
        'PACKTIVITY_ASYNCBACKEND',
        'packtivity.asyncbackends:ForegroundBackend:ForegroundProxy')

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p, _ = load_proxy(p.json())
    assert type(p) == ForegroundProxy
Example #4
0
def test_celery():
    from packtivity.asyncbackends import CeleryProxy
    from celery.result import AsyncResult
    asyncresult = AsyncResult('1234')
    p = CeleryProxy(asyncresult)

    p, _ = load_proxy(p.json())
    assert type(p) == CeleryProxy

    p.details()['task_id'] == asyncresult.task_id
Example #5
0
def test_celery():
    from packtivity.asyncbackends import CeleryProxy
    from celery.result import AsyncResult
    asyncresult = AsyncResult('1234')
    p = CeleryProxy(asyncresult)

    p,_ = load_proxy(p.json())
    assert type(p) == CeleryProxy

    p.details()['task_id'] == asyncresult.task_id
Example #6
0
    def fromJSON(cls, data, deserialization_opts = None):
        if data['task']['type'] == 'packtivity_task':
            task   = packtivity_task.fromJSON(data['task'], deserialization_opts)
            result = datamodel.create(data['result'],getattr(task.state,'datamodel',{})) if data['result'] else None
            instance = cls(data['name'], task, data['id'],result)

            adage.serialize.set_generic_data(instance,data)
            instance.resultproxy = load_proxy(data['proxy'],deserialization_opts, best_effort_backend = False) if data['proxy'] else None
            return instance
        else:
            raise RuntimeError('unknown task type',data['task']['type'])
Example #7
0
def checkproxy(jsonfile):
    proxydata = json.load(open(jsonfile))
    proxy, backend = bkutils.load_proxy(proxydata, best_effort_backend = True)

    ready = backend.ready(proxy)

    click.secho('ready: {}'.format(ready))
    if ready:
        successful = backend.successful(proxy)
        click.secho('successful: {}'.format(successful))
        if successful:
            result = backend.result(proxy)
            click.secho('result: {}'.format(json.dumps(result.json())))
Example #8
0
def checkproxy(jsonfile):
    proxydata = json.load(open(jsonfile))
    proxy, backend = bkutils.load_proxy(proxydata, best_effort_backend=True)

    ready = backend.ready(proxy)

    click.secho("ready: {}".format(ready))
    if ready:
        successful = backend.successful(proxy)
        click.secho("successful: {}".format(successful))
        if successful:
            result = backend.result(proxy)
            click.secho("result: {}".format(json.dumps(result.json())))
Example #9
0
    def fromJSON(cls, data, deserialization_opts=None):
        if data['task']['type'] == 'packtivity_task':
            task = packtivity_task.fromJSON(data['task'], deserialization_opts)
            result = TypedLeafs(data['result'],
                                getattr(task.state, 'datamodel',
                                        {})) if data['result'] else None
            instance = cls(data['name'], task, data['id'], result)

            adage.serialize.set_generic_data(instance, data)
            instance.resultproxy = load_proxy(
                data['proxy'], deserialization_opts,
                best_effort_backend=False) if data['proxy'] else None
            return instance
        else:
            raise RuntimeError('unknown task type', data['task']['type'])
Example #10
0
    def fromJSON(cls, data, deserialization_opts=None):
        if data["task"]["type"] == "packtivity_task":
            task = packtivity_task.fromJSON(data["task"], deserialization_opts)
            result = (
                datamodel.create(data["result"], getattr(task.state, "datamodel", {}))
                if data["result"]
                else None
            )
            instance = cls(data["name"], task, data["id"], result)

            adage.serialize.set_generic_data(instance, data)
            instance.resultproxy = (
                load_proxy(
                    data["proxy"], deserialization_opts, best_effort_backend=False
                )
                if data["proxy"]
                else None
            )
            return instance
        else:
            raise RuntimeError("unknown task type", data["task"]["type"])
Example #11
0
 def fromJSON(cls, data, deserialization_opts=None):
     deserialization_opts = deserialization_opts or {}
     p = load_proxy(data["proxy"],
                    deserialization_opts,
                    best_effort_backend=False)
     return cls(p, data["cacheid"])
Example #12
0
 def fromJSON(cls, data, deserialization_opts=None):
     deserialization_opts = deserialization_opts or {}
     return cls(load_proxy(data['proxy'], deserialization_opts),
                data['cacheid'],
                best_effort_backend=False)
Example #13
0
def test_foreground():
    from packtivity.asyncbackends import ForegroundProxy

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p, _ = load_proxy(p.json())
    assert type(p) == ForegroundProxy
Example #14
0
def test_python():
    from packtivity.asyncbackends import ForegroundProxy

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p = load_proxy(p.json(), {'proxy': 'py:packtivity.asyncbackends:ForegroundProxy'}, best_effort_backend = False)
    assert type(p) == ForegroundProxy
Example #15
0
def test_foreground():
    from packtivity.asyncbackends import ForegroundProxy

    p = ForegroundProxy({'hello': 'world'}, None, True)
    p,_ = load_proxy(p.json())
    assert type(p) == ForegroundProxy
Example #16
0
 def fromJSON(cls,data,deserialization_opts = None):
     deserialization_opts = deserialization_opts or {}
     return cls(load_proxy(data['proxy'],deserialization_opts), data['cacheid'],best_effort_backend = False)