Change to the new paging format with the commands available at the top.
This commit is contained in:
parent
dee6088b90
commit
6fd343741b
7 changed files with 213 additions and 140 deletions
|
@ -10,6 +10,10 @@ class BuildLogs(object):
|
|||
def _logs_key(build_id):
|
||||
return 'builds/%s/logs' % build_id
|
||||
|
||||
@staticmethod
|
||||
def _commands_key(build_id):
|
||||
return 'builds/%s/commands' % build_id
|
||||
|
||||
def append_log_entry(self, build_id, log_obj):
|
||||
"""
|
||||
Appends the serialized form of log_obj to the end of the log entry list
|
||||
|
@ -20,12 +24,30 @@ class BuildLogs(object):
|
|||
def append_log_message(self, build_id, log_message):
|
||||
"""
|
||||
Wraps the message in an envelope and push it to the end of the log entry
|
||||
list and returns the new length of the list.
|
||||
list and returns the index at which it was inserted.
|
||||
"""
|
||||
log_obj = {
|
||||
'message': log_message
|
||||
}
|
||||
return self._redis.rpush(self._logs_key(build_id), json.dumps(log_obj))
|
||||
return self._redis.rpush(self._logs_key(build_id), json.dumps(log_obj)) - 1
|
||||
|
||||
def append_command_message(self, build_id, command_message):
|
||||
"""
|
||||
Wraps the message in an envelope and push it to the end of the log entry
|
||||
list, to the commands list, and returns the new length of the list.
|
||||
"""
|
||||
log_obj = {
|
||||
'message': command_message,
|
||||
'is_command': True,
|
||||
}
|
||||
idx = self._redis.rpush(self._logs_key(build_id), json.dumps(log_obj)) - 1
|
||||
|
||||
cmd_obj = {
|
||||
'message': command_message,
|
||||
'index': idx,
|
||||
}
|
||||
self._redis.rpush(self._commands_key(build_id), json.dumps(cmd_obj))
|
||||
return idx
|
||||
|
||||
def get_log_entries(self, build_id, start_index, end_index):
|
||||
"""
|
||||
|
@ -37,6 +59,24 @@ class BuildLogs(object):
|
|||
end_index)
|
||||
return (llen, (json.loads(entry) for entry in log_entries))
|
||||
|
||||
def get_commands(self, build_id):
|
||||
"""
|
||||
Returns a list of all Dockerfile commands that have passed through the
|
||||
specified build thus far.
|
||||
"""
|
||||
commands = self._redis.lrange(self._commands_key(build_id), 0, -1)
|
||||
return (json.loads(cmd) for cmd in commands)
|
||||
|
||||
def get_last_command(self, build_id):
|
||||
"""
|
||||
Returns only the last command from the list of commands.
|
||||
"""
|
||||
commands = self._redis.lrange(self._commands_key(build_id), -1, -1)
|
||||
if commands:
|
||||
return json.loads(commands[-1])
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _status_key(build_id):
|
||||
return 'builds/%s/status' % build_id
|
||||
|
|
Reference in a new issue