autoland: add 'created' column and process transplants in order (
bug 1274482); r?smacleod
MozReview-Commit-ID: FuDQOpxKFPv
--- 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