Skip to content

Commit a7756fc

Browse files
committed
Respond quickly to buildkite pokes
Otherwise it thinks they have failed, as per comment.
1 parent 8cb7eee commit a7756fc

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎scripts/redeploy.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import glob
2020
import re
2121
import shutil
22+
import threading
23+
from Queue import Queue
2224

2325
from flask import Flask, jsonify, request, abort
2426

@@ -32,6 +34,8 @@
3234
arg_webhook_token = None
3335
arg_api_token = None
3436

37+
workQueue = Queue()
38+
3539
def create_symlink(source, linkname):
3640
try:
3741
os.symlink(source, linkname)
@@ -48,6 +52,16 @@ def req_headers():
4852
"Authorization": "Bearer %s" % (arg_api_token,),
4953
}
5054

55+
# Buildkite considers a poke to have failed if it has to wait more than 10s for
56+
# data (any data, not just the initial response) and it normally takes longer than
57+
# that to download an artifact from buildkite. Apparently there is no way in flask
58+
# to finish the response and then keep doing stuff, so instead this has to involve
59+
# threading. Sigh.
60+
def worker_thread():
61+
while True:
62+
toDeploy = workQueue.get()
63+
deploy_buildkite_artifact(*toDeploy)
64+
5165
@app.route("/", methods=["POST"])
5266
def on_receive_buildkite_poke():
5367
got_webhook_token = request.headers.get('X-Buildkite-Token')
@@ -129,7 +143,16 @@ def on_receive_buildkite_poke():
129143
abort(400, "Refusing to deploy artifact from URL %s", artifact_to_deploy['url'])
130144
return
131145

132-
return deploy_buildkite_artifact(artifact_to_deploy, pipeline_name, build_num)
146+
# there's no point building up a queue of things to deploy, so if there are any pending jobs,
147+
# remove them
148+
while not workQueue.empty():
149+
try:
150+
workQueue.get(False)
151+
except:
152+
pass
153+
workQueue.put([artifact_to_deploy, pipeline_name, build_num])
154+
155+
return jsonify({})
133156

134157
def deploy_buildkite_artifact(artifact, pipeline_name, build_num):
135158
artifact_response = requests.get(artifact['url'], headers=req_headers())
@@ -152,8 +175,6 @@ def deploy_buildkite_artifact(artifact, pipeline_name, build_num):
152175

153176
create_symlink(source=extracted_dir, linkname=arg_symlink)
154177

155-
return jsonify({})
156-
157178
def deploy_tarball(artifact, build_dir):
158179
"""Download a tarball from jenkins and unpack it
159180
@@ -281,4 +302,7 @@ def deploy_tarball(artifact, build_dir):
281302
deployer.symlink_paths,
282303
)
283304
)
305+
fred = threading.Thread(target=worker_thread)
306+
fred.daemon = True
307+
fred.start()
284308
app.run(port=args.port, debug=False)

0 commit comments

Comments
 (0)