예제 #1
0
파일: tasks.py 프로젝트: kadhikari/kirin-1
import requests
from kirin import gtfs_realtime_pb2
from kirin import core
import navitia_wrapper
from kirin.utils import make_rt_update
from kirin.exceptions import KirinException, InvalidArguments
from kirin.gtfs_rt.model_maker import KirinModelBuilder


#we don't want celery to mess with our logging configuration
@setup_logging.connect
def celery_setup_logging(*args, **kwargs):
    pass


celery = make_celery(app)


@task_postrun.connect
def close_session(*args, **kwargs):
    # Flask SQLAlchemy will automatically create new sessions for you from
    # a scoped session factory, given that we are maintaining the same app
    # context, this ensures tasks have a fresh session (e.g. session errors
    # won't propagate across tasks)
    model.db.session.remove()


from kirin.gtfs_rt.tasks import gtfs_poller


@celery.task(bind=True)
예제 #2
0
def try_to_ping_celery() -> bool:
    # TODO: if this is slow, cache the make_celery(app) part
    if len(make_celery(app).control.ping()) == 0:
        raise ValueError("No celery worker responding")
    return True