# Path: f8a_worker/monkey_patch.py
# def patch(self):
#     """Monkey Patching "Dispatcher.migrate_message" function to modify code at runtime."""
#     original_migrate_message = Dispatcher.migrate_message
# 
#     def patched_migrate_message(self, flow_info):
#         res = original_migrate_message(self, flow_info)
#         # Adding patch to throw error if the message is older than SQS_MSG_LIFETIME
#         _check_hung_task(self, flow_info)
#         return res
# 
#     Dispatcher.migrate_message = patched_migrate_message


import celery
import os
import raven
from f8a_worker.setup_celery import init_celery, init_selinon
from raven.contrib.celery import register_signal, register_logger_signal
from f8a_worker.monkey_patch import patch
#!/usr/bin/env python

"""Start the application."""



class SentryCelery(celery.Celery):
    """Celery class to configure sentry."""

    def on_configure(self):
        """Set up sentry client."""
        dsn = os.environ.get("SENTRY_DSN")
        client = raven.Client(dsn)
        register_logger_signal(client)
        register_signal(client)
        client.ignore_exceptions = [
            "f8a_worker.errors.NotABugFatalTaskError",
            "f8a_worker.errors.NotABugTaskError",
            "f8a_worker.errors.TaskAlreadyExistsError"
        ]

        # Patch to drain out old messages

# Path: f8a_worker/monkey_patch.py
# def patch(self):
#     """Monkey Patching "Dispatcher.migrate_message" function to modify code at runtime."""
#     original_migrate_message = Dispatcher.migrate_message
# 
#     def patched_migrate_message(self, flow_info):
#         res = original_migrate_message(self, flow_info)
#         # Adding patch to throw error if the message is older than SQS_MSG_LIFETIME
#         _check_hung_task(self, flow_info)
#         return res
# 
#     Dispatcher.migrate_message = patched_migrate_message


# Path: f8a_worker/start.py
import celery
import os
import raven
from f8a_worker.setup_celery import init_celery, init_selinon
from raven.contrib.celery import register_signal, register_logger_signal
from f8a_worker.monkey_patch import patch

#!/usr/bin/env python

"""Start the application."""



class SentryCelery(celery.Celery):
    """Celery class to configure sentry."""

    def on_configure(self):
        """Set up sentry client."""
        dsn = os.environ.get("SENTRY_DSN")
        client = raven.Client(dsn)
        register_logger_signal(client)
        register_signal(client)
        client.ignore_exceptions = [
            "f8a_worker.errors.NotABugFatalTaskError",
            "f8a_worker.errors.NotABugTaskError",
            "f8a_worker.errors.TaskAlreadyExistsError"
        ]

        # Patch to drain out old messages

        patch(self)