Skip to content

Commit

Permalink
Use list/dict comprehension (spotify#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
mivade authored and Tarrasch committed Jun 2, 2017
1 parent d9ecfd3 commit 29eef2a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions luigi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def get_template_path(self):
class AllRunHandler(BaseTaskHistoryHandler):
def get(self):
all_tasks = self._scheduler.task_history.find_all_runs()
tasknames = []
for task in all_tasks:
tasknames.append(task.name)
tasknames = [task.name for task in all_tasks]
# show all tasks with their name list to be selected
# why all tasks? the duration of the event history of a selected task
# can be more than 24 hours.
Expand All @@ -104,18 +102,16 @@ def get(self):

class SelectedRunHandler(BaseTaskHistoryHandler):
def get(self, name):
tasks = {}
statusResults = {}
taskResults = []
# get all tasks that has been updated
all_tasks = self._scheduler.task_history.find_all_runs()
# get events history for all tasks
all_tasks_event_history = self._scheduler.task_history.find_all_events()
for task in all_tasks:
task_seq = task.id
task_name = task.name
# build the dictionary, tasks with index: id, value: task_name
tasks[task_seq] = str(task_name)

# build the dictionary tasks with index: id, value: task_name
tasks = {task.id: str(task.name) for task in all_tasks}

for task in all_tasks_event_history:
# if the name of user-selected task is in tasks, get its task_id
if tasks.get(task.task_id) == str(name):
Expand Down

0 comments on commit 29eef2a

Please sign in to comment.