Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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 = ""
r = requests.get(URL)
if r.status_code != 200:
print('Failed to fetch resource')
data = r.json()
if not len(data['builds']):
print('No Builds')
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment