Skip to content

Commit 1e17bdb

Browse files
committed
workers: revision worker implementation
WIP DO NOT MERGE Commit message TBD - add abstract Worker class (bug 1744327) - add main worker flag and capacity/throttle flags - add many to many fields + association to revisions/landing jobs - add method to parse diff and list affected files - add more test coverage for revision_worker.py - add mots integration (bug 1740107) - add new RevisionWorker that pre-processes revisions (bug 1788728) - add new RevisionWorker that pre-processes revisions (bug 1788728) - add new start/stop commands to manage workers - add new flags to stop workers gracefully (*_WORKER_STOPPED) - add patch caching on disk - add proper loop/process functionality to workers - add repo.use_revision_worker feature flag (bug 1788732) - add mots hashes check - improved edge search functionality - implement stack hashes to detect changes in revisions (via get_stack_hashes) - include new Lando revision info via API endpoint - refactor dependency and stack fetching and parsing using networkx - refactored revision worker and landing worker to use Worker class - remove s3/boto/etc. dependencies (bug 1753728) - rename old command lando-cli landing-worker to lando-cli start-landing-worker - run pre/post mots query - store mots output in revision model
1 parent 024c18a commit 1e17bdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2563
-809
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
max-line-length = 88
33
select = C,E,F,W,B,B9
4-
ignore = E203, E501, W503, B006
4+
ignore = E203, E501, W503, B006, E712, E711
55
exclude =
66
.hg,
77
.git,

Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ RUN cd / && pip install --no-cache /app
5454
ENV PYTHONPATH /app
5555
RUN chown -R app:app /app
5656

57-
# Create repos directory for transplanting in landing-worker
57+
# Create repos directory for landing-worker and revision worker.
5858
RUN mkdir /repos
59+
RUN chown -R app:app /repos
60+
61+
# Create patches directory to cache patches.
62+
RUN mkdir /patches
63+
RUN chown -R app:app /patches
5964

6065
# Run as a non-privileged user
6166
USER app

Dockerfile-dev

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ENV PYTHONUNBUFFERED=1
2020
ENV FLASK_RUN_PORT=9000
2121
ENV FLASK_RUN_HOST=0.0.0.0
2222
ENV FLASK_DEBUG=1
23+
ENV HTTP_ALLOWED=1
2324

2425
ENTRYPOINT ["lando-cli"]
2526
CMD ["run"]
@@ -48,9 +49,14 @@ RUN cd / && pip install --no-cache /app
4849
ENV PYTHONPATH /app
4950
RUN chown -R app:app /app
5051

52+
# Create repos directory for landing worker and revision worker.
5153
RUN mkdir /repos
5254
RUN chown -R app:app /repos
5355

56+
# Create patches directory to store cached patches.
57+
RUN mkdir /patches
58+
RUN chown -R app:app /patches
59+
5460
# Run as a non-privileged user
5561
USER app
5662

docker-compose.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,24 @@ services:
131131
- smtp
132132
lando-api.landing-worker:
133133
image: lando-api
134-
command: ["landing-worker"]
134+
command: ["start-landing-worker"]
135135
environment:
136-
- ENV=localdev
137-
- DATABASE_URL=postgresql://postgres:[email protected]/lando_api_dev
138-
- SENTRY_DSN=
139-
# See http://docs.celeryproject.org/en/stable/getting-started/brokers/redis.html#configuration
140-
# for the full URL format.
141-
- CELERY_BROKER_URL=redis://redis.queue/0
142-
- OIDC_IDENTIFIER=https://lando-api.test
143-
- OIDC_DOMAIN=https://auth0.test
144-
- LANDO_UI_URL=https://lando.test
145-
- REPO_CLONES_PATH=/repos
146-
- REPOS_TO_LAND=localdev
136+
CELERY_BROKER_URL: "redis://redis.queue/0"
137+
DATABASE_URL: "postgresql://postgres:[email protected]/lando_api_dev"
138+
ENV: "localdev"
139+
LANDO_UI_URL: "https://lando.test"
140+
OIDC_DOMAIN: "https://auth0.test"
141+
OIDC_IDENTIFIER: "https://lando-api.test"
142+
REPOS_TO_LAND: "localdev"
143+
REPO_CLONES_PATH: "/repos"
144+
SENTRY_DSN: ""
147145
user: root
148146
volumes:
149147
- ./:/app
150148
- ./migrations/:/migrations/
151149
# Prevent writing python cache to the host.
152150
- caches_cache:/app/.cache/
151+
- repos:/repos
153152
depends_on:
154153
- lando-api.db
155154
- redis.queue
@@ -177,3 +176,5 @@ volumes:
177176
caches_pycache:
178177
caches_cache:
179178
caches_pytest_cache:
179+
repos:
180+
patches:

landoapi/api/landing_jobs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def put(landing_job_id: str, data: dict):
6262
)
6363

6464
if landing_job.status in (LandingJobStatus.SUBMITTED, LandingJobStatus.DEFERRED):
65-
landing_job.transition_status(LandingJobAction.CANCEL)
66-
db.session.commit()
65+
landing_job.transition_status(LandingJobAction.CANCEL, commit=True, db=db)
6766
return {"id": landing_job.id}, 200
6867
else:
6968
raise ProblemException(

landoapi/api/revisions.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from landoapi.decorators import require_phabricator_api_key
1111
from landoapi.models import SecApprovalRequest
1212
from landoapi.phabricator import PhabricatorClient
13+
from landoapi.models.revisions import Revision
1314
from landoapi.projects import get_secure_project_phid
1415
from landoapi.revisions import revision_is_secure
1516
from landoapi.secapproval import send_sanitized_commit_message_for_review
@@ -88,3 +89,15 @@ def request_sec_approval(phab: PhabricatorClient, data: dict):
8889
db.session.commit()
8990

9091
return {}, 200
92+
93+
94+
def get_stack_hashes(revision_id: int) -> tuple:
95+
"""
96+
Given a revision, returns revision stack hashes.
97+
98+
A stack hash is used to detect a change in a revision.
99+
"""
100+
revision = Revision.query.filter(Revision.id == revision_id).one_or_none()
101+
if revision:
102+
return revision.stack_hashes, 200
103+
return {}, 404

landoapi/api/stacks.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from flask import current_app
99
from landoapi.commit_message import format_commit_message
1010
from landoapi.decorators import require_phabricator_api_key
11+
from landoapi.models.revisions import Revision
1112
from landoapi.phabricator import PhabricatorClient
1213
from landoapi.projects import (
1314
get_release_managers,
@@ -116,19 +117,25 @@ def get(phab: PhabricatorClient, revision_id: str):
116117
}
117118

118119
revisions_response = []
119-
for revision_phid, revision in stack_data.revisions.items():
120-
fields = PhabricatorClient.expect(revision, "fields")
120+
for _phid, phab_revision in stack_data.revisions.items():
121+
lando_revision = Revision.query.filter(
122+
Revision.revision_id == phab_revision["id"]
123+
).one_or_none()
124+
revision_phid = PhabricatorClient.expect(phab_revision, "phid")
125+
fields = PhabricatorClient.expect(phab_revision, "fields")
121126
diff_phid = PhabricatorClient.expect(fields, "diffPHID")
122127
repo_phid = PhabricatorClient.expect(fields, "repositoryPHID")
123128
diff = stack_data.diffs[diff_phid]
124-
human_revision_id = "D{}".format(PhabricatorClient.expect(revision, "id"))
129+
human_revision_id = "D{}".format(PhabricatorClient.expect(phab_revision, "id"))
125130
revision_url = urllib.parse.urljoin(
126131
current_app.config["PHABRICATOR_URL"], human_revision_id
127132
)
128-
secure = revision_is_secure(revision, secure_project_phid)
129-
commit_description = find_title_and_summary_for_display(phab, revision, secure)
130-
bug_id = get_bugzilla_bug(revision)
131-
reviewers = get_collated_reviewers(revision)
133+
secure = revision_is_secure(phab_revision, secure_project_phid)
134+
commit_description = find_title_and_summary_for_display(
135+
phab, phab_revision, secure
136+
)
137+
bug_id = get_bugzilla_bug(phab_revision)
138+
reviewers = get_collated_reviewers(phab_revision)
132139
accepted_reviewers = reviewers_for_commit_message(
133140
reviewers, users, projects, sec_approval_project_phid
134141
)
@@ -163,16 +170,16 @@ def get(phab: PhabricatorClient, revision_id: str):
163170
{
164171
"id": human_revision_id,
165172
"phid": revision_phid,
166-
"status": serialize_status(revision),
173+
"status": serialize_status(phab_revision),
167174
"blocked_reason": blocked.get(revision_phid, ""),
168175
"bug_id": bug_id,
169176
"title": commit_description.title,
170177
"url": revision_url,
171178
"date_created": PhabricatorClient.to_datetime(
172-
PhabricatorClient.expect(revision, "fields", "dateCreated")
179+
PhabricatorClient.expect(phab_revision, "fields", "dateCreated")
173180
).isoformat(),
174181
"date_modified": PhabricatorClient.to_datetime(
175-
PhabricatorClient.expect(revision, "fields", "dateModified")
182+
PhabricatorClient.expect(phab_revision, "fields", "dateModified")
176183
).isoformat(),
177184
"summary": commit_description.summary,
178185
"commit_message_title": commit_message_title,
@@ -183,6 +190,9 @@ def get(phab: PhabricatorClient, revision_id: str):
183190
"reviewers": serialize_reviewers(reviewers, users, projects, diff_phid),
184191
"is_secure": secure,
185192
"is_using_secure_commit_message": commit_description.sanitized,
193+
"lando_revision": lando_revision.serialize()
194+
if lando_revision
195+
else None,
186196
}
187197
)
188198

0 commit comments

Comments
 (0)