Ejemplo n.º 1
0
    def kill(self, task_id=None, **kwargs):
        from mcloud.remote import Client

        client = Client(host=self.host, settings=self.settings)
        try:
            yield client.connect()
            success = yield client.terminate_task(task_id)

            if not success:
                print 'Task not found by id'

            else:
                print 'Task successfully treminated.'

        except ConnectionRefusedError:
            print 'Can\'t connect to mcloud server'

        client.shutdown()
        yield sleep(0.01)
Ejemplo n.º 2
0
    def kill(self, task_id=None, **kwargs):
        from mcloud.remote import Client

        client = Client(host=self.host, settings=self.settings)
        try:
            yield client.connect()
            success = yield client.terminate_task(task_id)

            if not success:
                print 'Task not found by id'

            else:
                print 'Task successfully treminated.'

        except ConnectionRefusedError:
            print 'Can\'t connect to mcloud server'

        client.shutdown()
        yield sleep(0.01)
Ejemplo n.º 3
0
def test_task_terminate():

    #-----------------------------------
    # preparations
    #-----------------------------------

    # cleanup a bit
    inject.clear()

    rc = yield redis.Connection(dbid=2)
    eb = EventBus(rc)
    yield eb.connect()

    def my_config(binder):
        binder.bind(redis.Connection, rc)
        binder.bind(EventBus, eb)
        binder.bind('settings', None)

    inject.configure(my_config)

    yield rc.flushdb()

    api = inject.instance(ApiRpcServer)

    #-----------------------------------
    # Test itself
    #-----------------------------------

    # this will emulate some long-running process
    task_defered = defer.Deferred()

    # this is mock that will execute our long-running process
    task = flexmock()
    task.should_receive('foo').with_args(
        int, 123, 'test').once().and_return(task_defered)

    # register our task
    api.tasks['baz'] = task.foo

    # start server -> real server on tcp port
    server = Server(port=9987, no_ssl=True)
    server.bind()

    # real client connecton here
    client = Client(port=9987, no_ssl=True)
    yield client.connect()

    # client calls a task
    task = Task('baz')
    yield client.call(task, 123, 'test')

    yield sleep(0.1)

    assert task.id > 0
    assert task.name == 'baz'

    assert task.is_running is True

    # now client terminates the task
    yield sleep(0.1)

    client.terminate_task(task.id)

    yield sleep(0.1)

    assert task.is_running is False

    #-----------------------------------
    # Cleanup
    #-----------------------------------

    client.shutdown()
    server.shutdown()

    yield sleep(0.1)
Ejemplo n.º 4
0
def test_task_terminate():

    #-----------------------------------
    # preparations
    #-----------------------------------

    # cleanup a bit
    inject.clear()

    rc = yield redis.Connection(dbid=2)
    eb = EventBus(rc)
    yield eb.connect()

    def my_config(binder):
        binder.bind(redis.Connection, rc)
        binder.bind(EventBus, eb)
        binder.bind('settings', None)

    inject.configure(my_config)

    yield rc.flushdb()

    api = inject.instance(ApiRpcServer)


    #-----------------------------------
    # Test itself
    #-----------------------------------

    # this will emulate some long-running process
    task_defered = defer.Deferred()


    # this is mock that will execute our long-running process
    task = flexmock()
    task.should_receive('foo').with_args(int, 123, 'test').once().and_return(task_defered)

    # register our task
    api.tasks['baz'] = task.foo

    # start server -> real server on tcp port
    server = Server(port=9987, no_ssl=True)
    server.bind()

    # real client connecton here
    client = Client(port=9987, no_ssl=True)
    yield client.connect()


    # client calls a task
    task = Task('baz')
    yield client.call(task, 123, 'test')

    yield sleep(0.1)

    assert task.id > 0
    assert task.name == 'baz'

    assert task.is_running is True


    # now client terminates the task
    yield sleep(0.1)

    client.terminate_task(task.id)

    yield sleep(0.1)

    assert task.is_running is False

    #-----------------------------------
    # Cleanup
    #-----------------------------------

    client.shutdown()
    server.shutdown()

    yield sleep(0.1)