Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stream log output to response #9

Open
mjallday opened this issue Aug 18, 2014 · 1 comment
Open

How to stream log output to response #9

mjallday opened this issue Aug 18, 2014 · 1 comment

Comments

@mjallday
Copy link
Contributor

Trying to figure out the easiest way to stream log output to the response since building is a slow process.

I'm thinking of

  1. Spin up a process and write data to a log file on disk and then read the file back as it's written.
  2. Spin up a background thread via gevent and run the builder there and pass a logger to it. Kind like https://stackoverflow.com/questions/24892418/background-thread-logging-to-a-server-sent-event-stream-in-a-flask-app
        messages_to_yield = []

        if result['build']:
            builder = forms.background_build(
                result['organization'], result['name'], result['commit'],
                log_stream=logger
            )

        class Handler(logging.Handler):

            def emit(self, record):
                msg = self.format(record)
                messages_to_yield.append(msg)

        logger.addHandler(Handler())

        def iterate_response():
            import time
            builder.start_build()
            while builder.building:
                time.sleep(1)
                for msg in messages_to_yield.pop():
                    yield msg

        return api.Response(app_iter=iterate_response())

Any opinions about the simplest way to do this?

@mjallday mjallday mentioned this issue Aug 19, 2014
Merged
2 tasks
@mjallday
Copy link
Contributor Author

currently implemented via gevent thread. probably better served as a worker task running in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant