Merge ~jugmac00/launchpad:add-explanation-for-codeimport into launchpad:master

Proposed by Jürgen Gmach
Status: Merged
Approved by: Jürgen Gmach
Approved revision: 171d1ab652a0175f8e90be917b90837b8f9b278b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~jugmac00/launchpad:add-explanation-for-codeimport
Merge into: launchpad:master
Diff against target: 84 lines (+70/-0)
2 files modified
doc/explanation/codeimport.rst (+68/-0)
doc/explanation/index.rst (+2/-0)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Simone Pelosi Approve
Review via email: mp+442815@code.launchpad.net

Commit message

Add explanation about how code imports work

To post a comment you must log in.
Revision history for this message
Simone Pelosi (pelpsi) wrote :

LGTM!

review: Approve
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM! Approved with comments.

review: Approve
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Suggest maybe adding an intro sentence for first time readers. Something along the lines of "Launchpad has the ability to constantly sync code from external repositories by setting up a code import" (and maybe also adding something about it being only one directional?)

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

@ines I understand "explanation" in the diátaxis context as something that deepens the understanding, and not as an introduction. So you usually use them when you know already something about a topic. That was the reason why I did not add an introduction in the first place. But I think adding one does not hurt. Thanks for the suggestion.

Revision history for this message
Jürgen Gmach (jugmac00) :
Revision history for this message
Guruprasad (lgp171188) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/doc/explanation/codeimport.rst b/doc/explanation/codeimport.rst
2new file mode 100644
3index 0000000..2f775da
4--- /dev/null
5+++ b/doc/explanation/codeimport.rst
6@@ -0,0 +1,68 @@
7+====================
8+Code import in depth
9+====================
10+
11+Launchpad has the ability to constantly sync code from external repositories by
12+setting up a code import. This is a one-way sync, from the external source to
13+Launchpad.
14+
15+Design decisions
16+================
17+
18+Code import / code mirroring is not triggered by the remote repository,
19+but it is rather triggered from the Launchpad side several times a day.
20+This should be fine for most use cases.
21+
22+The benefit of doing it this way is there is no need to install a webhook on
23+the remote repository to trigger an import or update of the repository.
24+
25+Frequency
26+=========
27+
28+While the current implementation has some support for setting it on a
29+per-import basis, that's actually not exposed right now.
30+
31+The frequency depends on the type of the revision control system, and is set in
32+``effective_update_interval``,
33+see https://git.launchpad.net/launchpad/tree/lib/lp/code/model/codeimport.py.
34+
35+As the default intervals in the config schema aren't overridden anywhere right
36+now, you can look them up in the ``codeimport`` section in the configuration
37+schema:
38+https://git.launchpad.net/launchpad/tree/lib/lp/services/config/schema-lazr.conf.
39+
40+Trigger code import
41+===================
42+
43+On a high level, each import has a database field, which indicates when the
44+next import should be performed. We could think of this as task queue.
45+
46+A scheduler queries the database, and in case there are jobs, a worker will
47+pick one up.
48+
49+Let's have a look in detail.
50+
51+After the import job runs, and if the import is still in the ``REVIEWED``
52+state, i.e. it hasn't failed too many times, or it hasn't been suspended or
53+similar, it then schedules a new job, that is, it sets a new date in the
54+``date_due`` column.
55+
56+Depending on the work load, there is no guarantee that a job will be picked up
57+in time, as the process works like this:
58+
59+- cronjobs in ``lp-codeimport`` run workers
60+- when the code import worker is looking for work to do, it calls
61+ ``getJobForMachine``,
62+ see https://git.launchpad.net/launchpad/tree/lib/lp/code/xmlrpc/codeimportscheduler.py
63+- that calls ``getJobForMachine``
64+ in https://git.launchpad.net/launchpad/tree/lib/lp/code/model/codeimportjob.py
65+ which makes a DB query to fetch the first job from a table that has
66+ ``due_date`` not in the future, and that is marked as ``pending``
67+- it then triggers the import
68+
69+Conclusion
70+==========
71+
72+The short answer is that we currently aim for every 12 hours for code imports
73+from CVS (very few nowadays), and every 6 hours from all other revision control
74+systems.
75diff --git a/doc/explanation/index.rst b/doc/explanation/index.rst
76index 21299fd..1ca8cb5 100644
77--- a/doc/explanation/index.rst
78+++ b/doc/explanation/index.rst
79@@ -14,3 +14,5 @@ Explanation
80 pip
81 favicon
82 charms
83+ codeimport
84+

Subscribers

People subscribed via source and target branches

to status/vote changes: