# Path: peekaboo/db.py
# DB_SCHEMA_VERSION = 9
# class InFlightSample(Base):
# class SampleInfo(Base):
# class PeekabooDatabase:
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, db_url, instance_id=0,
#                  stale_in_flight_threshold=15*60,
#                  log_level=logging.WARNING,
#                  async_driver=None):
#     def was_transient_error(self, error, attempt, action):
#     async def analysis_add(self, sample):
#     def analysis_update(self, sample):
#     def analysis_journal_fetch_journal(self, sample):
#     async def analysis_retrieve(self, job_id):
#     def mark_sample_in_flight(self, sample, instance_id=None, start_time=None):
#     def clear_sample_in_flight(self, sample, instance_id=None):
#     def clear_in_flight_samples(self, instance_id=None):
#     def clear_stale_in_flight_samples(self):
#         def clear_statement(statement_class):
#     def drop(self):


import asyncio
import email.utils
import logging
import urllib.parse
import sanic
import sanic.headers
import sanic.response
from peekaboo.db import PeekabooDatabaseError
            return sanic.response.json(
                {'message': 'No analysis result yet for job %d' % job_id}, 404)

        reason, result = job_info
        return sanic.response.json({
            'result': result.name,
            'reason': reason,
            # FIXME: depends on saving the report to the database
            # 'report': report,
            }, 200)

    def serve(self):
        """ Serves requests until shutdown is requested from the outside. """
        self.server = self.loop.run_until_complete(self.server_coroutine)

        # sanic 21.9 introduced an explicit startup that finalizes the app,
        # particularly the request routing. So we need to run it if present.
        if hasattr(self.server, 'startup'):
            self.loop.run_until_complete(self.server.startup())

        self.loop.run_until_complete(self.server.start_serving())
        logger.info('Peekaboo server is now listening on %s:%d',
                    self.host, self.port)
        self.loop.run_until_complete(self.server.wait_closed())
        logger.debug('Server shut down.')

    def shut_down(self):
        """ Triggers a shutdown of the server, used by the signal handler and
        potentially other components to cause the main loop to exit. """
        logger.debug('Server shutdown requested.')

# Path: peekaboo/db.py
# DB_SCHEMA_VERSION = 9
# class InFlightSample(Base):
# class SampleInfo(Base):
# class PeekabooDatabase:
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, db_url, instance_id=0,
#                  stale_in_flight_threshold=15*60,
#                  log_level=logging.WARNING,
#                  async_driver=None):
#     def was_transient_error(self, error, attempt, action):
#     async def analysis_add(self, sample):
#     def analysis_update(self, sample):
#     def analysis_journal_fetch_journal(self, sample):
#     async def analysis_retrieve(self, job_id):
#     def mark_sample_in_flight(self, sample, instance_id=None, start_time=None):
#     def clear_sample_in_flight(self, sample, instance_id=None):
#     def clear_in_flight_samples(self, instance_id=None):
#     def clear_stale_in_flight_samples(self):
#         def clear_statement(statement_class):
#     def drop(self):


# Path: peekaboo/server.py
import asyncio
import email.utils
import logging
import urllib.parse
import sanic
import sanic.headers
import sanic.response
from peekaboo.db import PeekabooDatabaseError

            return sanic.response.json(
                {'message': 'No analysis result yet for job %d' % job_id}, 404)

        reason, result = job_info
        return sanic.response.json({
            'result': result.name,
            'reason': reason,
            # FIXME: depends on saving the report to the database
            # 'report': report,
            }, 200)

    def serve(self):
        """ Serves requests until shutdown is requested from the outside. """
        self.server = self.loop.run_until_complete(self.server_coroutine)

        # sanic 21.9 introduced an explicit startup that finalizes the app,
        # particularly the request routing. So we need to run it if present.
        if hasattr(self.server, 'startup'):
            self.loop.run_until_complete(self.server.startup())

        self.loop.run_until_complete(self.server.start_serving())
        logger.info('Peekaboo server is now listening on %s:%d',
                    self.host, self.port)
        self.loop.run_until_complete(self.server.wait_closed())
        logger.debug('Server shut down.')

    def shut_down(self):
        """ Triggers a shutdown of the server, used by the signal handler and
        potentially other components to cause the main loop to exit. """
        logger.debug('Server shutdown requested.')

        if self.server is not None: