Merge lp:~liuyq0307/lava-scheduler/fix-861149 into lp:lava-scheduler

Proposed by Yongqin Liu
Status: Rejected
Rejected by: Michael Hudson-Doyle
Proposed branch: lp:~liuyq0307/lava-scheduler/fix-861149
Merge into: lp:lava-scheduler
Diff against target: 28 lines (+10/-1)
1 file modified
lava_scheduler_daemon/dbjobsource.py (+10/-1)
To merge this branch: bzr merge lp:~liuyq0307/lava-scheduler/fix-861149
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Disapprove
Review via email: mp+78990@code.launchpad.net

Description of the change

I am not very clear about the decorator of @transaction.commit_manually(),
but if I changed it to @transaction.commit_on_success(), there will be no this problem.

In my opinion, the submit_time and end_time is submitted in UTC, but the start_time is submitted in the local TIMEZONE of the server OS.
So if use utcnow to set start_time in getLogFileForJobOnBoard_impl method, it will be realized as local TIMEZONE time to commit to DB, instead of UTC time.

BTW,
1. after sentence "from django.db.models import Q", the timezone will be changed to UTC.
2. the TIMEZONE settings seems only useful for backend of PostgreSQL in django.db
   For the following description in django/db/_init__.py file.

# DatabaseWrapper.__init__() takes a dictionary, not a settings module, so
# we manually create the dictionary from the settings, passing only the
# settings that the database backends care about. Note that TIME_ZONE is used
# by the PostgreSQL backends.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

This is wrong, don't do this.

Using utcnow() is correct, rendering the timezone should be fixed instead. If we have legacy records that used now() vs utcnow() we can either fix them in the datbase or just ignore them.

Look up django's TZ setting for details.

review: Disapprove
Revision history for this message
Yongqin Liu (liuyq0307) wrote :

> This is wrong, don't do this.
>
> Using utcnow() is correct, rendering the timezone should be fixed instead. If
> we have legacy records that used now() vs utcnow() we can either fix them in
> the datbase or just ignore them.
>
> Look up django's TZ setting for details.

Do you mean to add one line [TIME_ZONE = 'GMT'] to the settings of lava-server
(file:lava-server/lava_server/settings/debian.py)?

If so, this doesn't make any change:(

Revision history for this message
Spring Zhang (qzhang) wrote :
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

For the record:

1) lava-server already uses GMT as anything else is broken by django design
2) All timestamps and dates in the database must use GMT/UTC
3) We can render timestamps with any offsets, this is a user preference

There is a bug somewhere that, most likely, records the wrong date in the database but this patch does not address that IMO.

Revision history for this message
Yongqin Liu (liuyq0307) wrote :

On 13 October 2011 21:01, Zygmunt Krynicki
<email address hidden>wrote:

> For the record:
>
> 1) lava-server already uses GMT as anything else is broken by django design
> 2) All timestamps and dates in the database must use GMT/UTC
> 3) We can render timestamps with any offsets, this is a user preference
>
> There is a bug somewhere that, most likely, records the wrong date in the
> database but this patch does not address that IMO.
>
In method getJobForBoard_impl, the start_time is utc time, but the commit
use it as local time to store into database,
I will look into the code deeper to see why the transaction commit does as
such.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

The problem turned out to be rather different from what might have been expected :(

Unmerged revisions

81. By Yongqin Liu

make start_time use local time to avoid the problem that start_time is before submit_time

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_scheduler_daemon/dbjobsource.py'
2--- lava_scheduler_daemon/dbjobsource.py 2011-08-22 03:20:17 +0000
3+++ lava_scheduler_daemon/dbjobsource.py 2011-10-11 14:49:24 +0000
4@@ -2,6 +2,15 @@
5 import json
6 import logging
7
8+import time
9+old_altzone=time.altzone
10+
11+class TZ(datetime.tzinfo):
12+ def utcoffset(self, dt):
13+ return datetime.timedelta(seconds=-old_altzone)
14+ def dst(self, dt):
15+ return datetime.timedelta(0)
16+
17 from django.core.files.base import ContentFile
18 from django.db import connection
19 from django.db import IntegrityError, transaction
20@@ -73,7 +82,7 @@
21 if jobs:
22 job = jobs[0]
23 job.status = TestJob.RUNNING
24- job.start_time = datetime.datetime.utcnow()
25+ job.start_time = datetime.datetime.now(TZ())
26 job.actual_device = device
27 device.status = Device.RUNNING
28 device.current_job = job

Subscribers

People subscribed via source and target branches