Add support for the remaining events to the frontend and the backend
This commit is contained in:
parent
f7c154abb5
commit
af31bde997
7 changed files with 269 additions and 40 deletions
|
@ -25,6 +25,7 @@ from collections import defaultdict
|
|||
from data import model
|
||||
from workers.worker import Worker, WorkerUnhealthyException, JobException
|
||||
from app import userfiles as user_files, build_logs, sentry, dockerfile_build_queue
|
||||
from endpoints.common import spawn_notification
|
||||
from util.safetar import safe_extractall
|
||||
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile
|
||||
|
||||
|
@ -501,6 +502,27 @@ class DockerfileBuildWorker(Worker):
|
|||
|
||||
build_dir = self._mime_processors[c_type](docker_resource)
|
||||
|
||||
# Spawn a notification that the build has started.
|
||||
event_data = {
|
||||
'build_id': repository_build.uuid,
|
||||
'build_name': repository_build.display_name,
|
||||
'docker_tags': tag_names,
|
||||
'trigger_id': repository_build.trigger.uuid,
|
||||
'trigger_kind': repository_build.trigger.service.name
|
||||
}
|
||||
|
||||
spawn_notification(repository, 'build_start', event_data,
|
||||
subpage='build?current=' % repository_build.uuid,
|
||||
pathargs=['build', repository_build.uuid])
|
||||
|
||||
# Setup a handler for spawning failure messages.
|
||||
def spawn_failure(message, event_data):
|
||||
event_data['error_message'] = exc.message
|
||||
spawn_notification(repository, 'build_failure', event_data,
|
||||
subpage='build?current=' % repository_build.uuid,
|
||||
pathargs=['build', repository_build.uuid])
|
||||
|
||||
# Start the build process.
|
||||
try:
|
||||
with DockerfileBuildContext(build_dir, build_subdir, repo, tag_names, access_token,
|
||||
repository_build.uuid, self._cache_size_gb,
|
||||
|
@ -541,21 +563,38 @@ class DockerfileBuildWorker(Worker):
|
|||
repository_build.phase = 'complete'
|
||||
repository_build.save()
|
||||
|
||||
# Spawn a notification that the build has completed.
|
||||
spawn_notification(repository, 'build_success', event_data,
|
||||
subpage='build?current=' % repository_build.uuid,
|
||||
pathargs=['build', repository_build.uuid])
|
||||
|
||||
except WorkerUnhealthyException as exc:
|
||||
# Need a separate handler for this so it doesn't get caught by catch all below
|
||||
# Spawn a notification that the build has failed.
|
||||
spawn_failure(exc.message, event_data)
|
||||
|
||||
# Raise the exception to the queue.
|
||||
raise exc
|
||||
|
||||
except JobException as exc:
|
||||
# Need a separate handler for this so it doesn't get caught by catch all below
|
||||
# Spawn a notification that the build has failed.
|
||||
spawn_failure(exc.message, event_data)
|
||||
|
||||
# Raise the exception to the queue.
|
||||
raise exc
|
||||
|
||||
except Exception as exc:
|
||||
# Spawn a notification that the build has failed.
|
||||
spawn_failure(exc.message, event_data)
|
||||
|
||||
# Write the error to the logs.
|
||||
sentry.client.captureException()
|
||||
log_appender('error', build_logs.PHASE)
|
||||
logger.exception('Exception when processing request.')
|
||||
repository_build.phase = 'error'
|
||||
repository_build.save()
|
||||
log_appender(str(exc), build_logs.ERROR)
|
||||
|
||||
# Raise the exception to the queue.
|
||||
raise JobException(str(exc))
|
||||
|
||||
|
||||
|
|
Reference in a new issue