autoland: add 'created' column and process transplants in order (bug 1274482); r?smacleod draft
authorbyron jones <glob@mozilla.com>
Tue, 24 May 2016 01:10:58 +0800
changeset 8168 f92ddb235cc3656795cd3912fd6e363244d55db7
parent 8167 ecbf0da1a3ce9a38a97527a2ef982563a74451a9
push id855
push userbjones@mozilla.com
push dateMon, 23 May 2016 17:11:39 +0000
reviewerssmacleod
bugs1274482
autoland: add 'created' column and process transplants in order (bug 1274482); r?smacleod MozReview-Commit-ID: FuDQOpxKFPv
autoland/autoland/autoland.py
autoland/sql/0009-add-created.sql
autoland/sql/schema.sql
--- a/autoland/autoland/autoland.py
+++ b/autoland/autoland/autoland.py
@@ -33,20 +33,21 @@ MOZREVIEW_RETRY_DELAY = datetime.timedel
 # time to wait before retrying a transplant
 TRANSPLANT_RETRY_DELAY = datetime.timedelta(minutes=5)
 
 
 def handle_pending_transplants(logger, dbconn):
     cursor = dbconn.cursor()
     now = datetime.datetime.now()
     query = """
-        select id, destination, request
-        from Transplant
-        where landed is null and (last_updated is null
-            or last_updated<=%(time)s)
+        SELECT id, destination, request
+        FROM Transplant
+        WHERE landed IS NULL
+              AND (last_updated IS NULL OR last_updated<=%(time)s)
+        ORDER BY created
     """
     transplant_retry_delay = TRANSPLANT_RETRY_DELAY
     if config.testing():
         transplant_retry_delay = datetime.timedelta(seconds=1)
 
     cursor.execute(query, ({'time': now - transplant_retry_delay}))
 
     current_treestatus = {}
new file mode 100644
--- /dev/null
+++ b/autoland/sql/0009-add-created.sql
@@ -0,0 +1,3 @@
+--This adds a created column to the transplant table so requests can be
+--processed in the same order they were requested.
+alter table transplant add column created timestamp not null default current_timestamp
--- a/autoland/sql/schema.sql
+++ b/autoland/sql/schema.sql
@@ -5,16 +5,17 @@ grant usage, select on sequence request_
 
 create table Transplant (
     id bigint default nextval('request_sequence'),
     destination varchar(255),
     request json,
     landed boolean,
     result text,
     last_updated timestamp,
+    created timestamp not null default current_timestamp,
     primary key(id)
 );
 grant all privileges on table Transplant to autoland;
 
 create table MozreviewUpdate (
     id bigserial primary key,
     transplant_id bigint references transplant(id),
     data text