"""Asynchronous tasks"""
from django_rq import job

from buildservice.errors import MissingToken
from buildservice.models import Build, OAuthToken
from buildservice.utils import github


@job
def execute_build(build_id):
    """
    Execute a given build.
    """
    build = Build.objects.get(pk=build_id)
    token = OAuthToken.objects.filter(user__webhook__repository=build.repository).first()
    if not token:
        raise MissingToken('Cannot find token for build %s' % build_id)

    # TODO: do stuff

    status = 'success'
    build.status = status
    build.save()
    github.create_status(
        token.value, build.repository, build.sha,
        state=status, target_url=build.url
    )

@@ -67,122 +67,27 @@
 ice.
-errors import MissingToken%0Afrom buildservice.models import Build, OAuthToken%0Afrom buildservice.utils import github
+models import Build
 %0A%0A%0A@
@@ -209,398 +209,96 @@
 id)%0A
+%0A
     
-token = OAuthToken.objects.filter(user__webhook__repository=build.repository).first()%0A    if not token:%0A        raise MissingToken('Cannot find token for build %25s' %25 build_id)%0A%0A    # TODO: do stuff%0A%0A    status = 'success'%0A    build.status = status%0A    build.save()%0A    github.create_status(%0A        token.value, build.repository, build.sha,%0A        state=status, target_url=build.url%0A    
+# when build complete...%0A    status = 'success'%0A    build.update_status(status, token
 )%0A

simplify the execute_build() task to use Build.update_status()