Last active
September 6, 2016 21:04
-
-
Save equalsraf/e83aff6f063c75ae95e113aabf46c663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# | |
# Little script to check if Appveyor is stuck | |
# | |
# The return code is (2) if the build is considered stuck, (0) if not | |
# stuck, and (1) for other errors | |
import json | |
import sys | |
import requests | |
# python-dateutil | |
import dateutil.parser | |
import datetime | |
# Consider it stuck after 1 day waiting for a queued build | |
TRESHOLD = datetime.timedelta(1) | |
# Fetch latest 1000 jobs | |
URL = "http://ci.appveyor.com/api/projects/neovim/neovim/history?recordsNumber=1000" | |
r = requests.get(URL) | |
if r.status_code != 200: | |
print('Failed to fetch resource') | |
sys.exit(1) | |
data = r.json() | |
if not len(data['builds']): | |
print('No Builds') | |
sys.exit(0) | |
print('Checking builds since %s' % data['builds'][-1]['started']) | |
# Last finished build | |
finished = [build for build in data['builds'] if build['status'] in ('failed', 'success')] | |
if len(finished): | |
b = finished[0] | |
started = dateutil.parser.parse(b['started']).strftime('%d %b %Y %H:%M') | |
finished = dateutil.parser.parse(b['finished']).strftime('%d %b %Y %H:%M') | |
print('- Last finished build:%s started:%s finished:%s' % (b['buildId'], started, finished)) | |
# Ignore cancelled or finished builds | |
builds = [build for build in data['builds'] if build['status'] not in ('cancelled', 'success', 'failed')] | |
# queued builds | |
queued = [build for build in builds if build['status'] == 'queued'] | |
print('- There are %d queued builds' % len(queued)) | |
oldest = datetime.datetime.utcnow() | |
if queued: | |
for job in queued: | |
created = dateutil.parser.parse(job['created']).replace(tzinfo=None) | |
if created < oldest: | |
oldest = created | |
print('- The oldest job was created in %s' % oldest.strftime('%d %b %Y %H:%M')) | |
if datetime.datetime.utcnow() - oldest > TRESHOLD: | |
# Appveyor seems stuck, return error | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment