0

I am currently developing a music streaming service from the ground up. I'm doing both, back and front end. I have a server that I'm using for testing during this development phase. It has a Go server application and also a clone of a GitHub repo where I push my Vue.js code for the front end.

The deployment process is simple. Once I push changes to the master branch, I'd ssh into the server, cd into the Vue.js project folder, git pull, npm run build and voila! Since it is such an easy and predictable task, I wanted to automate it using GitHub's webhooks and Python's Flask framework. So I've written this (and it kinda works):

# this snippet only shows the important bits

def onpush(event: str, info: Dict):
    subprocess.run(SCRIPT, stdout=LOG_FILE)

@app.route('/github', methods=['POST'])
def github() -> str:
    if request.headers['Content-Type'] != 'application/json':
        return '415 - unsupported media type'

    event: str = request.headers['X-GitHub-Event']
    info: Dict = request.json
    onpush(event, info) # takes too long! client times out since ...
    return '200 - OK'   # this return value is used as the response ...
                        # which means it's not sent until `onpush` is done

However, the onpush function runs git pull within its subprocess.run call (which takes time to fetch data from GitHub servers), and none of it is concurrent. So, using route's return '200 - OK' value as the server's response (which is what Flask does if I'm not mistaken) leads to the fact that:

  1. GitHub webhoook client times out and displays payload as undelivered (even though on the server-side everything worked fine - it's just that client couldn't wait long enough to get the response they are expecting).
  2. I cannot respond first and then call onpush since responding = returning from function.

Webhooks call timed out

So I am pretty much looking for a way to get this thing to respond quickly enough so that GitHub will not time out while still being able to git pull. This could probably be resolved with a bit of concurrency or threading but I really don't know how.

  • you should make it asynchronous. I would recommend creating a tracking ID once you get the API call and then trigger a new process in non blocking mode and capture logs against the tracking ID so that you can refer back to logs with a mapping in hand in case of any failure. – akazuko Apr 24 '20 at 07:55
  • Hey, @akazuko could you show me how to do that? This is the [link to repo](https://github.com/sharpvik/morty-cd) for more context. – Viktor Rozenko Apr 24 '20 at 07:59

0 Answers0