Exemple #1
0
        current_user.update_lat()


def make_celery(app=None):
    app = app or create_app()[0]
    celery.conf.update(app.config)
    ext = FlaskCeleryExt(app)
    return ext.celery


# Health-check
health = HealthCheck(current_app, "/health-check")
health.add_check(health_check_celery)
health.add_check(health_check_db)
with current_app.app_context():
    current_app.config['MIGRATION_STATUS'] = check_migrations()
health.add_check(health_check_migrations)


# http://stackoverflow.com/questions/9824172/find-out-whether-celery-task-exists
@after_task_publish.connect
def update_sent_state(sender=None, headers=None, **kwargs):
    # the task may not exist if sent using `send_task` which
    # sends tasks by name, so fall back to the default result backend
    # if that is the case.
    task = celery.tasks.get(sender)
    backend = task.backend if task else celery.backend
    backend.store_result(headers['id'], None, 'WAITING')


# register celery tasks. removing them will cause the tasks to not function. so don't remove them
    def test_migrations(self):
        """Method to test the database migrations"""

        with self.app.test_request_context():
            result = check_migrations().split(',')
            assert result[0] == 'success'
            with app.app_context():
                return task_base.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery


celery = make_celery(current_app)

# Health-check
health = HealthCheck(current_app, "/health-check")
envdump = EnvironmentDump(current_app, "/environment", include_config=False)
health.add_check(health_check_celery)
health.add_check(health_check_db)
with current_app.app_context():
    current_app.config['MIGRATION_STATUS'] = check_migrations()
health.add_check(health_check_migrations)


# http://stackoverflow.com/questions/9824172/find-out-whether-celery-task-exists
@after_task_publish.connect
def update_sent_state(sender=None, body=None, **kwargs):
    # the task may not exist if sent using `send_task` which
    # sends tasks by name, so fall back to the default result backend
    # if that is the case.
    task = celery.tasks.get(sender)
    backend = task.backend if task else celery.backend
    backend.store_result(body['id'], None, 'WAITING')


# register celery tasks. removing them will cause the tasks to not function. so don't remove them
    def test_migrations(self):
        """Method to test the database migrations"""

        with app.test_request_context():
            result = check_migrations().split(',')
            self.assertEqual(result[0], 'success')
Exemple #5
0
 def test_migrations(self):
     with app.test_request_context():
         result = check_migrations().split(',')
         self.assertEqual(result[0], 'success')