Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Query for the current task correctly
Browse files Browse the repository at this point in the history
Summary:
We don't really make use of `Task.id`, we use `Task.task_id`, which is really `child_id`.
The original logic was broken due to this conclusion; this updates to query for the actual
primary key, and adjusts the tests accordingly.
Once this works, the additional logging will be removed.

Test Plan: Unit

Reviewers: anupc

Reviewed By: anupc

Subscribers: changesbot

Differential Revision: https://tails.corp.dropbox.com/D220573
  • Loading branch information
kylec1 committed Aug 16, 2016
1 parent 01a6b5a commit dd7d63e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Task(db.Model):

id = Column(GUID, primary_key=True, default=uuid.uuid4)
task_name = Column(String(128), nullable=False)
# TODO: Rename 'task_id' to 'child_id' in code to make things less confusing.
task_id = Column('child_id', GUID, nullable=False)
parent_id = Column(GUID)
status = Column(Enum(Status), nullable=False, default=Status.unknown)
Expand Down
6 changes: 5 additions & 1 deletion changes/queue/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,11 @@ def _report_lag(self, first_run_time):
first_run_time (datetime): When the task started running.
"""
# type: (datetime) -> None
t = Task.query.get(self.task_id)
t = Task.query.filter(
Task.task_name == self.task_name,
Task.task_id == self.task_id,
Task.parent_id == self.parent_id
).first()
# Ensure the task exists, and that the creation and modification date
# are the same (meaning we're at the first run).
if t and t.date_created == t.date_modified:
Expand Down
3 changes: 2 additions & 1 deletion tests/changes/queue/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def test_report_lag(self):
creation_date = datetime(2016, 8, 12, 17, 42, 27)
fresh_task = self.create_task(
task_name='success_task',
task_id=UUID('94bec3a1-592d-4734-b84b-55ba0226e5d1'),
date_created=creation_date,
status=Status.queued,
)
success_task.task_id = fresh_task.id
success_task.task_id = fresh_task.task_id

fake_stats = mock.Mock(spec=Stats)
with mock.patch.object(statsreporter, 'stats') as get_stats:
Expand Down

0 comments on commit dd7d63e

Please sign in to comment.