Esempio n. 1
0
def spawn_universe_tasks():
    """ Task triggered every XX minutes (not less than 5) that trigger
    'universe' tasks (market prices, industry indexes, ...) """
    now = utcnow()

    # checking if API is up. If not, just stop it
    if not is_server_online():
        logger.info('Looks like EVE is still down / in VIP mode. Skipping !')
        return

    for task in UNIVERSE_TASKS:
        if not is_task_running(None, task.__name__):
            task_id = "%s-%s" % (
                now.strftime('%Y%m%d-%H%M%S'),
                task.__name__,
            )
            token_state = TaskState(
                task_id=task_id,
                id=None,
                scope=task.__name__,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s().apply_async(task_id=task_id)
Esempio n. 2
0
def spawn_universe_tasks():
    """ Task triggered every XX minutes (not less than 5) that trigger
    'universe' tasks (market prices, industry indexes, ...) """
    now = utcnow()

    # checking if API is up. If not, just stop it
    if not is_server_online():
        logger.info('Looks like EVE is still down / in VIP mode. Skipping !')
        return

    for task in UNIVERSE_TASKS:
        if not is_task_running(None, task.__name__):
            task_id = "%s-%s" % (
                now.strftime('%Y%m%d-%H%M%S'),
                task.__name__,
            )
            token_state = TaskState(
                task_id=task_id,
                id=None,
                scope=task.__name__,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s().apply_async(task_id=task_id)
Esempio n. 3
0
def spawn_market_price_tasks(self):
    """Celery task to spawn market prices update tasks"""
    self.start()
    region_list = Region.query.filter(Region.id.in_(
        config.ESI_REGION_PRICE)).all()

    for region in region_list:
        if not is_task_running(region.id,
                               task_update_region_order_price.__name__):
            item_id_list = [
                it[0] for it in db.session.query(ItemPrice.item_id).filter_by(
                    region_id=region.id)
            ]

            task_id = "%s-%s-%s" % (utcnow().strftime('%Y%m%d-%H%M%S'),
                                    task_update_region_order_price.__name__,
                                    region.name)
            token_state = TaskState(
                task_id=task_id,
                id=region.id,
                scope=task_update_region_order_price.__name__,
            )
            db.session.add(token_state)
            db.session.commit()

            task_update_region_order_price.s(
                region.id, item_id_list).apply_async(task_id=task_id)

    self.end(TaskState.SUCCESS)
Esempio n. 4
0
def spawn_character_tasks():
    """ Task triggered every minutes that scan all tasks done to find
    any character based task to do (based on the cached_until field) """
    now = utcnow()

    # checking if API is up. If not, just stop it
    if not is_server_online():
        logger.info('Looks like EVE is still down / in VIP mode. Skipping !')
        return

    all_tokens = TokenScope.query.filter_by(valid=True).all()

    for token_scope in all_tokens:
        if skip_scope(token_scope):
            continue

        # check if there is no running task, and the data is not still cached
        if (not is_task_running(token_scope.user_id, token_scope.scope) and
            (not token_scope.cached_until or token_scope.cached_until <= now)):

            task = CHAR_TASK_SCOPE[token_scope.scope]
            task_id = "%s-%s-%s" % (now.strftime('%Y%m%d-%H%M%S'),
                                    task.__name__, token_scope.user_id)
            token_state = TaskState(
                task_id=task_id,
                id=token_scope.user_id,
                scope=token_scope.scope,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s(token_scope.user_id).apply_async(task_id=task_id)
Esempio n. 5
0
def spawn_character_tasks():
    """ Task triggered every minutes that scan all tasks done to find
    any character based task to do (based on the cached_until field) """
    now = utcnow()

    all_tokens = TokenScope.query.all()

    for token_scope in all_tokens:
        if skip_scope(token_scope):
            continue

        # check if there is no running task, and the data is not still cached
        if ((not token_scope.cached_until or token_scope.cached_until <= now)
                and
                not is_task_running(token_scope.user_id, token_scope.scope)):

            task = CHAR_TASK_SCOPE[token_scope.scope]
            task_id = "%s-%s-%s" % (now.strftime('%Y%m%d-%H%M%S'),
                                    task.__name__, token_scope.user_id)
            token_state = TaskState(
                task_id=task_id,
                id=token_scope.user_id,
                scope=token_scope.scope,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s(token_scope.user_id).apply_async(task_id=task_id)
Esempio n. 6
0
def spawn_universe_tasks():
    """ Task triggered every XX minutes (not less than 5) that trigger
    'universe' tasks (market prices, industry indexes, ...) """
    now = utcnow()
    for task in UNIVERSE_TASKS:
        if not is_task_running(None, task.__name__):
            task_id = "%s-%s" % (
                now.strftime('%Y%m%d-%H%M%S'),
                task.__name__,
            )
            token_state = TaskState(
                task_id=task_id,
                id=None,
                scope=task.__name__,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s().apply_async(task_id=task_id)
Esempio n. 7
0
def spawn_market_price_tasks(self):
    """Celery task to spawn market prices update tasks"""
    self.start()
    region_list = Region.query.filter(
        Region.id.in_(config.ESI_REGION_PRICE)
    ).all()

    for region in region_list:
        if not is_task_running(region.id,
                               task_update_region_order_price.__name__):
            item_id_list = [
                it[0] for it in db.session.query(
                    ItemPrice.item_id
                ).filter_by(region_id=region.id)
            ]

            task_id = "%s-%s-%s" % (
                utcnow().strftime('%Y%m%d-%H%M%S'),
                task_update_region_order_price.__name__,
                region.name
            )
            token_state = TaskState(
                task_id=task_id,
                id=region.id,
                scope=task_update_region_order_price.__name__,
            )
            db.session.add(token_state)
            db.session.commit()

            task_update_region_order_price.s(
                region.id,
                item_id_list
            ).apply_async(
                task_id=task_id
            )

    self.end(TaskState.SUCCESS)
Esempio n. 8
0
def spawn_character_tasks():
    """ Task triggered every minutes that scan all tasks done to find
    any character based task to do (based on the cached_until field) """
    now = utcnow()

    # checking if API is up. If not, just stop it
    if not is_server_online():
        logger.info('Looks like EVE is still down / in VIP mode. Skipping !')
        return

    all_tokens = TokenScope.query.filter_by(valid=True).all()

    for token_scope in all_tokens:
        if skip_scope(token_scope):
            continue

        # check if there is no running task, and the data is not still cached
        if (not is_task_running(token_scope.user_id, token_scope.scope) and
                (not token_scope.cached_until or
                    token_scope.cached_until <= now)):

            task = CHAR_TASK_SCOPE[token_scope.scope]
            task_id = "%s-%s-%s" % (
                now.strftime('%Y%m%d-%H%M%S'),
                task.__name__,
                token_scope.user_id
            )
            token_state = TaskState(
                task_id=task_id,
                id=token_scope.user_id,
                scope=token_scope.scope,
            )
            db.session.add(token_state)
            db.session.commit()

            task.s(token_scope.user_id).apply_async(task_id=task_id)