Пример #1
0
def temp():
    # synchronous
    print(add(4, 4))

    # Asynchronous
    task = add.delay(4, 4)
    print(task)

    print(AsyncResult(task.task_id).get())

    # synchronous
    print(add.delay(4, 4).get())
Пример #2
0
        def run_jobs():
            lock = threading.RLock()
            lock.acquire()
            session = meta.Session
            log.info(source + 'Started scheduled background jobs')

            # add task is for debug
            total = tasks.add(2, 3)
            print total

            try:
                log.info(source + "Checking ueb model build request status")
                from routes import request_config
                from routes.mapper import Mapper
                config = request_config()
                config.mapper = Mapper()
                config.host = '127.0.0.1:5000'
                config.protocol = 'http'
                #if hasattr(config, 'using_request_local'):
                config.request_local = tasks.check_ueb_request_process_status()
                config = request_config()
                    #tasks.check_ueb_request_process_status()
                log.info(source + "UEB model build request status check finished")
            except Exception as e:
                log.error(source + 'Failed to check ueb package build request status.\nException:%s' % e)
                pass
            try:
                log.info(source + "Retrieving ueb model package from app server")
                tasks.retrieve_ueb_packages()
                log.info(source + "Retrieving ueb model package from app server was successful")
            except Exception as e:
                log.error(source + 'Failed to retrieve ueb package from app server.\nException:%s' % e)
                pass

            try:
                log.info(source + "Checking ueb model run status")
                tasks.check_ueb_run_status()
                log.info(source + "UEB model run status check finished")
            except Exception as e:
                log.error(source + 'Failed to check ueb package run status.\nException:%s' % e)
                pass
            try:
                log.info(source + "Retrieving ueb model output package from app server")
                tasks.retrieve_ueb_run_output_packages()
                log.info(source + "Retrieving ueb model output package from app server was successful")
            except Exception as e:
                log.error(source + 'Failed to retrieve ueb model output package from app server.\nException:%s' % e)
                pass

            session.remove()
            log.info(source + 'Finished scheduled background jobs')
            time.sleep(interval * 60)
            lock.release()
Пример #3
0
def attachTask(id, newTaskId, accessToken=None):
    '''
    This adds a task ID to the tasks array. It doesn't create a new task.

    :param id:
    :param newTaskId:
    :param accessToken:
    :return:
    '''

    mylist = _get(id)

    if not mylist:
        logging.error("List with id %s doesn't exist!", id)
        return False

    tasks = mylist['tasks'] or []
    tasks = set(tasks)
    tasks.add(newTaskId)
    mylist['tasks'] = list(tasks)

    print "tasks: %s" % str(mylist)

    return _update(id, mylist)
def db_with_4_tasks(tasks_db, tasks_for_same_user):
    for t in tasks_for_same_user:
        tasks.add(t)
 def test_valid_id(self, task):
     """ We can use the same data for multiple tests."""
     task_id = tasks.add(task)
     t_from_db = tasks.get(task_id)
     assert t_from_db.id == task_id
def test_add_4(task):
    """ Slightly different take. """
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
def test_add_2(task):
    """ Demonstrate parametrize with 1 parameter."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #8
0
def test_add_5(task):
    """Demonstrate ids."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #9
0
 def test_valid_id(self, task):
     """Мы можем использовать одни и те же данные или несколько тестов."""
     task_id = tasks.add(task)
     t_from_db = tasks.get(task_id)
     assert t_from_db.id == task_id
Пример #10
0
def test_add_5(task):
    """Демонстрация ids."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #11
0
def test_add_3(summary, owner, done):
    """Демонстрирует параметризацию с одним параметром."""
    task = Task(summary, owner, done)
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #12
0
import os
if os.environ.get('WORKER_CLASS') in ('greenlet', 'gevent'):
    print('Monkey-patching for gevent.')
    from gevent import monkey; monkey.patch_all()
import sys

from config import huey
from tasks import add


if __name__ == '__main__':
    if sys.version_info[0] == 2:
        input = raw_input

    print('Huey Demo -- adds two numbers.')
    a = int(input('a = '))
    b = int(input('b = '))
    result = add(a, b)
    print('Result:')
    print(result.get(True))
Пример #13
0
def test_add_1():
    """tasks.get() using id returned from get() works."""
    task = Task('breathe', 'BRIAN', True)
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(task, t_from_db)
Пример #14
0
def test_add_5(tasks_db, c_task):
    task_id = tasks.add(c_task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, c_task)
Пример #15
0
def test_add_raises():
    """add() should raise an exception with wrong type param."""
    with pytest.raises(TypeError):
        tasks.add(task='Not a Task object')
Пример #16
0
def db_with_multi_per_owner(tasks_db, tasks_mult_per_owner):
    """Connected db with 9 tasks, 3 owners, all with 3 tasks."""
    for t in tasks_mult_per_owner:
        tasks.add(t)
Пример #17
0
def db_with_3_tasks(tasks_db, tasks_just_a_few):
    """Connected db with 3 tasks, all unique."""
    for t in tasks_just_a_few:
        tasks.add(t)
Пример #18
0
 def get(self):
     self.finish("Hello, %s" % add(3, 4))
Пример #19
0
def test_add_2(task):
    """Демонстрирует параметризацию с одним параметром."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
def test_add_1():
    task = Task('breathe', 'BRIAN', True)
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #21
0
def test_add_4(task):
    """Немного разные."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
def test_add_3(summary, owner, done):
    task = Task('summary', owner, done)
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(task, t_from_db)
Пример #23
0
 def test_equivalent(self, task):
     """Похожий тест, только внутри класса."""
     task_id = tasks.add(task)
     t_from_db = tasks.get(task_id)
     assert equivalent(t_from_db, task)
 def test_valid_id(self, task):
     task_id = tasks.add(task)
     t_from_db = tasks.get(task_id)
     assert t_from_db.id == task_id
def test_raises():
    with pytest.raises(TypeError):
        tasks.add(task='Not a Task object')
def test_add_6(task):
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
def test_add_6(task):
    """Demonstrate pytest.param and id."""
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #28
0
def db_with_3_tasks(initialized_db, tasks_just_a_few):
    for t in tasks_just_a_few:
        tasks.add(t)
def test_add_3(summary, owner, done):
    """Demonstrate parametrize with multiple parameters."""
    task = Task(summary, owner, done)
    task_id = tasks.add(task)
    t_from_db = tasks.get(task_id)
    assert equivalent(t_from_db, task)
Пример #30
0
def db_with_multi_per_owner(initialized_db, tasks_mult_per_owner):
    for t in tasks_mult_per_owner:
        tasks.add(t)
 def test_equivalent(self, task):
     """ Similar test, just within a class. """
     task_id = tasks.add(task)
     t_from_db = tasks.get(task_id)
     assert equivalent(t_from_db, task)
Пример #32
0
def test_added_task_has_id_set(tasks_db):
    new_task = Task('sit in chair', owner='me', done=True)
    task_id = tasks.add(new_task)
    task_from_db = tasks.get(task_id)
    assert task_from_db.id == task_id
Пример #33
0
 def test_missing_summary(self):
     """Should raise an exception if summary missing."""
     with pytest.raises(ValueError):
         tasks.add(Task(owner='bob'))
Пример #34
0
def test_add_increases_count(db_with_3_tasks):
    tasks.add(Task('throw a party'))
    assert tasks.count() == 4
Пример #35
0
from tasks import add


print(">>> from tasks import add")
print(">>> add(4, 4)")
res = add(4, 4)
print(repr(res))

print(">>> add.delay(4, 4)")
res = add.delay(4, 4)
print(repr(res))

print(">>> add.delay(4, 4).wait()")
res = add.delay(4, 4).wait()
print(repr(res))
Пример #36
0
def test_add_returns_valid_id(tasks_db):
    new_task = Task('do something')
    task_id = tasks.add(new_task)
    assert isinstance(task_id, int)