@neralabs/rerail-pack-celery 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +461 -2
- package/pack.json +180 -0
- package/package.json +35 -4
- package/rules/celery-practice-countdown-past-visibility-timeout.rerail +462 -0
- package/rules/celery-practice-dispatch-before-commit.rerail +467 -0
- package/rules/celery-practice-pickle-serializer.rerail +128 -0
- package/rules/celery-practice-result-get-in-task.rerail +210 -0
- package/rules/celery-practice-task-arg-not-serializable.rerail +279 -0
- package/rules/celery-practice-unknown-task-name.rerail +281 -0
- package/rules/lib/celery.rerail +683 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
.policy "celery-practice-unknown-task-name" revision 1
|
|
2
|
+
.description "Name Celery tasks by strings that match a registered task; a worker discards messages for unknown names, so a mistyped beat entry never runs."
|
|
3
|
+
.language python
|
|
4
|
+
.mode log
|
|
5
|
+
.scope include "**/*.py"
|
|
6
|
+
// Rerail's own rule, not a port. Celery sends only a task's name; the worker looks it up in its registry, and for a
|
|
7
|
+
// name no task registered it logs "Received unregistered task of type ..." and discards the message
|
|
8
|
+
// (celery/worker/consumer/consumer.py, UNKNOWN_TASK_ERROR). A beat entry whose "task" has a typo, or names a task that
|
|
9
|
+
// was renamed or moved to another module, is sent on schedule and dropped every time: the job silently never runs.
|
|
10
|
+
// Reported, at the naming site, when no task of the run is registered under the name and the run owns it:
|
|
11
|
+
// - the first argument (or `name=`) of `send_task(...)` on a Celery app (lib/celery's cel_app_ref or cel_app_value:
|
|
12
|
+
// a resolved app, a factory's result, current_app, `self.app`), of celery's `signature(...)` and of
|
|
13
|
+
// `<app>.signature(...)`;
|
|
14
|
+
// - the "task" of a beat schedule entry: a dict (a literal or `dict(...)`) with a "task" and a "schedule" key
|
|
15
|
+
// (Celery's documented entry shape), or with a "task" and an "options" key when its value reaches the beat
|
|
16
|
+
// setting: it lies in a beat_schedule setting's value (lib/celery's cel_setting), in an item assigned to or an
|
|
17
|
+
// `.update(...)` of that setting, in a module constant one of those reads (through imports, `**` splats
|
|
18
|
+
// included), or in a run function such a value calls, or one it reaches through the call graph (paperless-ngx
|
|
19
|
+
// lists its entries with "options" in `parse_beat_schedule()` and adds each cron from the environment).
|
|
20
|
+
// The name is a string literal, or a constant the engine resolves: a module constant of the run (through imports,
|
|
21
|
+
// re-exports and module aliases), a class attribute (`ExportTask.name`) or a local of its function, each bound once.
|
|
22
|
+
// A task is registered under its `name=` (such a value), else under <module>.<def>, which a string matches also by a
|
|
23
|
+
// dotted tail; `app.task(fn)` and `shared_task(name=...)(fn)` called as functions register the same way. A class
|
|
24
|
+
// deriving from celery's Task (through the run's classes, or `<app>.Task`) is registered under its `name = ...`
|
|
25
|
+
// attribute (such a value), else <module>.<Class>; a class whose `name` does not resolve registers nothing. The run
|
|
26
|
+
// owns a name n when n's module part (before the last dot) is exactly a module of the run, or when the run registers
|
|
27
|
+
// tasks under explicit dotted names that share n's first segment (`name="reports.scheduler"`). When a task with n's
|
|
28
|
+
// last segment as its def name exists elsewhere (a moved task), the message names it.
|
|
29
|
+
// "task": "proj.tasks.shipp" reported (proj/tasks.py defines `ship`)
|
|
30
|
+
// app.send_task("proj.tasks.ship") not reported (`@shared_task def ship` in proj/tasks.py)
|
|
31
|
+
// app.send_task("billing.charge") not reported (no module `billing` in the run: another service's task)
|
|
32
|
+
// remote.send_task("tasks.upload") not reported (the run has `proj/tasks.py`, but no module `tasks`)
|
|
33
|
+
// ML_JOBS = [{"task": "proj.x.y", "options": {...}}] not reported (never reaches the beat setting)
|
|
34
|
+
// Left alone: Celery's own tasks (`celery.*`, the names celery/app/builtins.py registers; the one name list kept,
|
|
35
|
+
// since a run module named `celery` would otherwise own them); a library's tasks (`django_celery_beat.*`), unowned
|
|
36
|
+
// unless the library is part of the run, where its tasks are registered; names whose module part is not a module of
|
|
37
|
+
// the run and whose first segment no explicit task name shares (another service's tasks: send_task is often used
|
|
38
|
+
// exactly for that); `send_task` on an object that is no Celery app; names built at runtime (f-strings, parameters,
|
|
39
|
+
// constants bound more than once); commented-out entries; test code (cel_test_doc).
|
|
40
|
+
// Gaps: tasks registered by a decorator wrapper that computes the name; a task name held by a constant outside the run;
|
|
41
|
+
// task modules autodiscovered from outside the run (an installed package); a run whose module names carry an extra
|
|
42
|
+
// leading package the worker does not (`api.tasks.x`, which the worker imports as `tasks.x`) does not own `tasks.*`;
|
|
43
|
+
// beat entries an app builds at runtime (`add_periodic_task`, django_celery_beat's PeriodicTask rows); whether the
|
|
44
|
+
// worker actually imports the module that defines the task (`include`/`imports`/autodiscover) is not checked.
|
|
45
|
+
|
|
46
|
+
#include "lib/celery.rerail"
|
|
47
|
+
|
|
48
|
+
.violation UnknownTaskName(at: node, n: symbol) "No task in this code registers \"{n}\", so a worker would discard it. Check it against the worker's registered tasks; leave it if another service or an installed package registers it."
|
|
49
|
+
.violation MovedTaskName(at: node, n: symbol, q: symbol) "No task registers \"{n}\"; a task \"{q}\" has its function name, so it may have moved. Check the worker's registered tasks; leave it if another service or a package registers it."
|
|
50
|
+
// What the run registers, owns and uses are facts of the whole run, over names alone (uk_unknown, uk_moved:
|
|
51
|
+
// cross_file). Each naming site is stated in its own file, with the string it holds (uk_ref) or the constant it reads
|
|
52
|
+
// (uk_ref_sym, a symbol another file binds: uk_const), and what it needs of other files (uk_holds).
|
|
53
|
+
UnknownTaskName(at, n) :- uk_ref(at, n, nq, nk), uk_holds(nq, nk), uk_unknown(n), !uk_moved(n, _), uk_live(at).
|
|
54
|
+
UnknownTaskName(at, n) :- uk_ref_sym(at, q, nq, nk), uk_holds(nq, nk), uk_const(q, n), uk_unknown(n), !uk_moved(n, _),
|
|
55
|
+
uk_live(at).
|
|
56
|
+
MovedTaskName(at, n, q) :- uk_ref(at, n, nq, nk), uk_holds(nq, nk), uk_unknown(n), uk_moved(n, q), uk_live(at).
|
|
57
|
+
MovedTaskName(at, n, mq) :- uk_ref_sym(at, q, nq, nk), uk_holds(nq, nk), uk_const(q, n), uk_unknown(n),
|
|
58
|
+
uk_moved(n, mq), uk_live(at).
|
|
59
|
+
.decl uk_live(at: node)
|
|
60
|
+
uk_live(at) :- docof(at, d), !cel_test_doc(d).
|
|
61
|
+
|
|
62
|
+
// ---- needs -------------------------------------------------------------------------------------------------------
|
|
63
|
+
// uk_holds(q, k): lib/celery's cel_is, and this rule's own kinds, closed over the run by symbol: "uk_beat_var" (a
|
|
64
|
+
// module variable whose value reaches the beat setting), "uk_beat_fn" (a run function whose result reaches it) and
|
|
65
|
+
// "uk_tcls" (celery's Task, or a class of the run deriving from it or from `<app>.Task`). It spans files on purpose
|
|
66
|
+
// (a beat setting reads a constant another module binds); symbols alone: cross_file.
|
|
67
|
+
.decl uk_holds(q: symbol, k: symbol) cross_file
|
|
68
|
+
uk_holds(q, k) :- cel_is(q, k).
|
|
69
|
+
uk_holds(q, "uk_beat_var") :- uk_var_beat_if(q, nq, nk), uk_holds(nq, nk).
|
|
70
|
+
uk_holds(q, "uk_beat_var") :- uk_var_read(q, nq, nk), uk_holds(nq, nk).
|
|
71
|
+
uk_holds(gq, "uk_beat_fn") :- uk_fn_call(gq, nq, nk), uk_holds(nq, nk).
|
|
72
|
+
uk_holds(hq, "uk_beat_fn") :- uk_holds(gq, "uk_beat_fn"), reach(gq, hq).
|
|
73
|
+
uk_holds("celery.Task", "uk_tcls"). uk_holds("celery.app.task.Task", "uk_tcls").
|
|
74
|
+
uk_holds(q, "uk_tcls") :- uk_tcls_if(q, nq, nk), uk_holds(nq, nk).
|
|
75
|
+
|
|
76
|
+
// ---- values ------------------------------------------------------------------------------------------------------
|
|
77
|
+
// uk_str_here(v, n): v is the string n, or a local name of its own function bound once to it. uk_str_sym(v, q): v is
|
|
78
|
+
// a name or attribute resolving to q, a module constant of the run (cel_sym follows imports, re-exports and module
|
|
79
|
+
// aliases) or a class attribute (`Cls.name`), whose value uk_const states in its own file.
|
|
80
|
+
.decl uk_str_here(v: node, n: symbol)
|
|
81
|
+
uk_str_here(v, n) :- str(v, n).
|
|
82
|
+
uk_str_here(v, n) :- unparen(v, u), kind(u, "identifier"), text(u, x), look(u, x, s), !kind(s, "module"),
|
|
83
|
+
asg(s, x, w, _), str(w, n), count : { asg(s, x, _, _) } = 1.
|
|
84
|
+
.decl uk_str_sym(v: node, q: symbol)
|
|
85
|
+
uk_str_sym(v, q) :- unparen(v, u), (kind(u, "identifier") ; kind(u, "attribute")), cel_sym(u, q).
|
|
86
|
+
// uk_const(q, n): q, a module constant or a class attribute bound once, is the string n. Stated in q's own file.
|
|
87
|
+
.decl uk_const(q: symbol, n: symbol)
|
|
88
|
+
uk_const(@dot(mq, x), n) :- modnode(_, m), modname(m, mq), asg(m, x, w, _), str(w, n), count : { asg(m, x, _, _) } = 1.
|
|
89
|
+
uk_const(@dot(cq, x), n) :- class_def(c, cq), asg(c, x, w, _), str(w, n), count : { asg(c, x, _, _) } = 1.
|
|
90
|
+
|
|
91
|
+
// ---- the names the run uses --------------------------------------------------------------------------------------
|
|
92
|
+
// uk_site(e, how, nq, nk): expression e is where a task is named: send_task's first argument or `name=`,
|
|
93
|
+
// signature's first argument, a beat entry's "task".
|
|
94
|
+
.decl uk_site(e: node, how: symbol, nq: symbol, nk: symbol)
|
|
95
|
+
uk_site(e, "send_task", nq, nk) :- kind(c, "call"), field(c, "function", fn), attr_of(fn, o, "send_task"),
|
|
96
|
+
unparen(o, u), (cel_app_ref(u, nq, nk) ; cel_app_value(u, nq, nk)), (posarg(c, 0, e) ; call_arg(c, -1, "name", e)).
|
|
97
|
+
uk_site(e, "signature", "", "") :- kind(c, "call"), field(c, "function", fn), sym_of(fn, q),
|
|
98
|
+
(q = "celery.signature" ; q = "celery.canvas.signature" ; q = "celery.canvas.Signature" ; q = "celery.Signature" ;
|
|
99
|
+
q = "celery.subtask" ; q = "celery.canvas.subtask"),
|
|
100
|
+
posarg(c, 0, e).
|
|
101
|
+
uk_site(e, "signature", nq, nk) :- kind(c, "call"), field(c, "function", fn), attr_of(fn, o, "signature"),
|
|
102
|
+
unparen(o, u), (cel_app_ref(u, nq, nk) ; cel_app_value(u, nq, nk)), posarg(c, 0, e).
|
|
103
|
+
uk_site(e, "beat", "", "") :- uk_entry_key(m, "task", e), uk_entry_key(m, "schedule", _).
|
|
104
|
+
uk_site(e, "beat", nq, nk) :- uk_entry_key(m, "task", e), uk_entry_key(m, "options", _), uk_beat_part(m, nq, nk).
|
|
105
|
+
// uk_entry_key(m, k, v): m is a dict literal with the string key k, or a `dict(...)` call with the keyword k; v its
|
|
106
|
+
// value.
|
|
107
|
+
.decl uk_entry_key(m: node, k: symbol, v: node)
|
|
108
|
+
uk_entry_key(m, k, v) :- kind(m, "dictionary"), child(m, p, _), kind(p, "pair"), field(p, "key", kn), str(kn, k),
|
|
109
|
+
field(p, "value", v).
|
|
110
|
+
uk_entry_key(m, k, v) :- kind(m, "call"), field(m, "function", f), builtin_ref(f, "dict"), call_arg(m, -1, k, v).
|
|
111
|
+
// ---- what reaches the beat setting -------------------------------------------------------------------------------
|
|
112
|
+
// uk_beat_expr(e, nq, nk): e's value reaches the beat setting: a beat_schedule setting's value, the value of an item
|
|
113
|
+
// assigned to the setting or of its `.update(...)`, the value of a module constant that reaches it ("uk_beat_var":
|
|
114
|
+
// one read in a beat expression or in a beat function, through imports).
|
|
115
|
+
.decl uk_beat_expr(e: node, nq: symbol, nk: symbol)
|
|
116
|
+
uk_beat_expr(u, "", "") :- cel_setting("beat_schedule", v, _), unparen(v, u).
|
|
117
|
+
uk_beat_expr(u, nq, nk) :- kind(a, "assignment"), field(a, "left", l), kind(l, "subscript"), field(l, "value", t),
|
|
118
|
+
uk_beat_target(t, nq, nk), field(a, "right", v), unparen(v, u).
|
|
119
|
+
uk_beat_expr(u, nq, nk) :- kind(c, "call"), field(c, "function", f), attr_of(f, t, "update"),
|
|
120
|
+
uk_beat_target(t, nq, nk), call_arg(c, _, _, v), unparen(v, u).
|
|
121
|
+
uk_beat_expr(u, q, "uk_beat_var") :- cel_module_var(q, w), unparen(w, u).
|
|
122
|
+
// uk_beat_read(r, nq, nk): r is a beat expression or lies in one.
|
|
123
|
+
.decl uk_beat_read(r: node, nq: symbol, nk: symbol)
|
|
124
|
+
uk_beat_read(e, nq, nk) :- uk_beat_expr(e, nq, nk).
|
|
125
|
+
uk_beat_read(r, nq, nk) :- uk_beat_expr(e, nq, nk), within(r, e).
|
|
126
|
+
// uk_var_beat_if(q, nq, nk): module variable q's own value reaches the beat setting (a beat_schedule setting's
|
|
127
|
+
// value). uk_var_read(q, nq, nk): q is read in a beat expression, or in a function ("uk_beat_fn"). Each stated in
|
|
128
|
+
// its own file, by symbol.
|
|
129
|
+
.decl uk_var_beat_if(q: symbol, nq: symbol, nk: symbol)
|
|
130
|
+
uk_var_beat_if(q, nq, nk) :- cel_module_var(q, w), unparen(w, u), uk_beat_expr(u, nq, nk).
|
|
131
|
+
.decl uk_var_read(q: symbol, nq: symbol, nk: symbol)
|
|
132
|
+
uk_var_read(q, nq, nk) :- uk_beat_read(r, nq, nk), (kind(r, "identifier") ; kind(r, "attribute")), cel_run_var(r, q).
|
|
133
|
+
uk_var_read(q, gq, "uk_beat_fn") :- kind(g, "function_definition"), within(r, g),
|
|
134
|
+
(kind(r, "identifier") ; kind(r, "attribute")), cel_run_var(r, q), qualname(g, gq).
|
|
135
|
+
// uk_fn_call(g, nq, nk): a beat expression calls run function g (`CELERY_BEAT_SCHEDULE = parse_beat_schedule()`); the
|
|
136
|
+
// functions g reaches through the call graph (python/calls' reach) are beat functions too (uk_holds).
|
|
137
|
+
.decl uk_fn_call(g: symbol, nq: symbol, nk: symbol)
|
|
138
|
+
uk_fn_call(gq, nq, nk) :- uk_beat_read(c, nq, nk), kind(c, "call"), field(c, "function", f), cel_run_def(f, gq).
|
|
139
|
+
// uk_beat_target(t, nq, nk): t is the beat setting: `<x>.conf.beat_schedule`, or a name bound to a beat expression
|
|
140
|
+
// (`CELERY_BEAT_SCHEDULE`, a celeryconfig's `beat_schedule`).
|
|
141
|
+
.decl uk_beat_target(t: node, nq: symbol, nk: symbol)
|
|
142
|
+
uk_beat_target(t, "", "") :- attr_of(t, o, "beat_schedule"), attr_of(o, _, "conf").
|
|
143
|
+
uk_beat_target(t, q, "uk_beat_var") :- (kind(t, "identifier") ; kind(t, "attribute")), cel_run_var(t, q).
|
|
144
|
+
// uk_beat_part(m, nq, nk): dict m reaches the beat setting: it lies in a beat expression, or in a beat function.
|
|
145
|
+
.decl uk_beat_part(m: node, nq: symbol, nk: symbol)
|
|
146
|
+
uk_beat_part(m, nq, nk) :- uk_entry_key(m, "options", _), uk_beat_read(m, nq, nk).
|
|
147
|
+
uk_beat_part(m, gq, "uk_beat_fn") :- uk_entry_key(m, "options", _), kind(g, "function_definition"), within(m, g),
|
|
148
|
+
qualname(g, gq).
|
|
149
|
+
// uk_ref(e, n, nq, nk): site e names the task n. uk_ref_sym(e, q, nq, nk): site e names the task uk_const(q, _).
|
|
150
|
+
.decl uk_ref(e: node, n: symbol, nq: symbol, nk: symbol)
|
|
151
|
+
uk_ref(e, n, nq, nk) :- uk_site(e, _, nq, nk), uk_str_here(e, n).
|
|
152
|
+
.decl uk_ref_sym(e: node, q: symbol, nq: symbol, nk: symbol)
|
|
153
|
+
uk_ref_sym(e, q, nq, nk) :- uk_site(e, _, nq, nk), uk_str_sym(e, q).
|
|
154
|
+
|
|
155
|
+
// ---- the names the run registers ---------------------------------------------------------------------------------
|
|
156
|
+
// uk_reg(n, how): a task of the run is registered as n, "explicit" (a name= or a class's name attribute) or "implicit"
|
|
157
|
+
// (<module>.<def>, <module>.<Class>). A fact of the whole run (cross_file, names alone), from what each file states
|
|
158
|
+
// of its own tasks: uk_reg_here (a string), uk_reg_sym (a constant, uk_const).
|
|
159
|
+
.decl uk_reg(n: symbol, how: symbol) cross_file
|
|
160
|
+
uk_reg(n, how) :- uk_reg_here(n, how, nq, nk), uk_holds(nq, nk).
|
|
161
|
+
uk_reg(n, how) :- uk_reg_sym(q, how, nq, nk), uk_holds(nq, nk), uk_const(q, n).
|
|
162
|
+
.decl uk_reg_here(n: symbol, how: symbol, nq: symbol, nk: symbol)
|
|
163
|
+
.decl uk_reg_sym(q: symbol, how: symbol, nq: symbol, nk: symbol)
|
|
164
|
+
uk_reg_here(n, "explicit", nq, nk) :- cel_task_option(_, "name", v, nq, nk), uk_str_here(v, n).
|
|
165
|
+
uk_reg_sym(q, "explicit", nq, nk) :- cel_task_option(_, "name", v, nq, nk), uk_str_sym(v, q).
|
|
166
|
+
uk_reg_here(n, "implicit", nq, nk) :- cel_task_name(f, n, nq, nk), !cel_task_named_opt(f).
|
|
167
|
+
// `app.task(fn)`, `app.task(fn, name=...)`, `shared_task(name=...)(fn)` called as functions, fn a def or class of
|
|
168
|
+
// the run.
|
|
169
|
+
uk_reg_here(n, "explicit", nq, nk) :- uk_wrap_call(c, nq, nk), uk_wrap_name(c, v), uk_str_here(v, n).
|
|
170
|
+
uk_reg_sym(q, "explicit", nq, nk) :- uk_wrap_call(c, nq, nk), uk_wrap_name(c, v), uk_str_sym(v, q).
|
|
171
|
+
uk_reg_here(q, "implicit", nq, nk) :- uk_wrap_call(c, nq, nk), !uk_wrap_named(c), posarg(c, 0, a), cel_run_def(a, q).
|
|
172
|
+
.decl uk_wrap_call(c: node, nq: symbol, nk: symbol)
|
|
173
|
+
uk_wrap_call(c, nq, nk) :- kind(c, "call"), field(c, "function", fn), cel_task_fn(fn, nq, nk), posarg(c, 0, a),
|
|
174
|
+
cel_run_def(a, _).
|
|
175
|
+
uk_wrap_call(c, nq, nk) :- kind(c, "call"), field(c, "function", k), kind(k, "call"), field(k, "function", fn),
|
|
176
|
+
cel_task_fn(fn, nq, nk), posarg(c, 0, a), cel_run_def(a, _).
|
|
177
|
+
.decl uk_wrap_name(c: node, v: node)
|
|
178
|
+
uk_wrap_name(c, v) :- kind(c, "call"), call_arg(c, -1, "name", v).
|
|
179
|
+
uk_wrap_name(c, v) :- kind(c, "call"), field(c, "function", k), kind(k, "call"), call_arg(k, -1, "name", v).
|
|
180
|
+
.decl uk_wrap_named(c: node)
|
|
181
|
+
uk_wrap_named(c) :- uk_wrap_name(c, _).
|
|
182
|
+
// A task class: registered under its `name` attribute (such a value), else <module>.<Class>.
|
|
183
|
+
uk_reg_here(n, "explicit", nq, nk) :- uk_task_class(c, nq, nk), uk_class_name_attr(c, v), uk_str_here(v, n).
|
|
184
|
+
uk_reg_sym(q, "explicit", nq, nk) :- uk_task_class(c, nq, nk), uk_class_name_attr(c, v), uk_str_sym(v, q).
|
|
185
|
+
uk_reg_here(@dot(mq, x), "implicit", nq, nk) :- uk_task_class(c, nq, nk), !uk_class_named(c), def_name(c, x),
|
|
186
|
+
docof(c, d), doc(d, _, mq), mq != "", nearest(c, m, scope), kind(m, "module").
|
|
187
|
+
// uk_task_class(c, nq, nk): c derives from celery's Task, directly, through `<app>.Task`, or through the run's
|
|
188
|
+
// classes ("uk_tcls" of a base). uk_tcls_if: the same by symbol, for the classes deriving from c.
|
|
189
|
+
.decl uk_task_class(c: node, nq: symbol, nk: symbol)
|
|
190
|
+
uk_task_class(c, b, "uk_tcls") :- kind(c, "class_definition"), cel_class_base(c, b).
|
|
191
|
+
uk_task_class(c, nq, nk) :- kind(c, "class_definition"), field(c, "superclasses", al), child(al, e, _),
|
|
192
|
+
attr_of(e, o, "Task"), unparen(o, u), (cel_app_ref(u, nq, nk) ; cel_app_value(u, nq, nk)).
|
|
193
|
+
.decl uk_tcls_if(q: symbol, nq: symbol, nk: symbol)
|
|
194
|
+
uk_tcls_if(q, nq, nk) :- uk_task_class(c, nq, nk), class_def(c, q).
|
|
195
|
+
// uk_class_name_attr(c, v): `name = v` in c's body (any value: one that does not resolve registers no implicit name).
|
|
196
|
+
.decl uk_class_name_attr(c: node, v: node)
|
|
197
|
+
uk_class_name_attr(c, v) :- kind(c, "class_definition"), field(c, "body", b), body_stmt(b, s, _),
|
|
198
|
+
kind(s, "expression_statement"), child(s, a, 0), kind(a, "assignment"), field(a, "left", l), text(l, "name"),
|
|
199
|
+
field(a, "right", v).
|
|
200
|
+
.decl uk_class_named(c: node)
|
|
201
|
+
uk_class_named(c) :- uk_class_name_attr(c, _).
|
|
202
|
+
|
|
203
|
+
// ---- the names asked about ---------------------------------------------------------------------------------------
|
|
204
|
+
// uk_name(n): a string some site names a task by (a superset: whatever its site needs). uk_unknown(n): no task of
|
|
205
|
+
// the run registers n, the run owns n, and n is none of Celery's own. Facts of the whole run, over names alone.
|
|
206
|
+
.decl uk_name(n: symbol) cross_file
|
|
207
|
+
uk_name(n) :- uk_ref_name(n).
|
|
208
|
+
uk_name(n) :- uk_ref_const(q), uk_const(q, n).
|
|
209
|
+
.decl uk_ref_name(n: symbol)
|
|
210
|
+
uk_ref_name(n) :- uk_ref(_, n, _, _).
|
|
211
|
+
.decl uk_ref_const(q: symbol)
|
|
212
|
+
uk_ref_const(q) :- uk_ref_sym(_, q, _, _).
|
|
213
|
+
.decl uk_unknown(n: symbol) cross_file
|
|
214
|
+
uk_unknown(n) :- uk_name(n), !uk_known(n), uk_owned(n), !uk_celery_own(n).
|
|
215
|
+
.decl uk_known(n: symbol)
|
|
216
|
+
uk_known(n) :- uk_name(n), uk_reg(n, _).
|
|
217
|
+
uk_known(n) :- uk_name(n), uk_reg(q, "implicit"), suffix(cat(".", n), q).
|
|
218
|
+
|
|
219
|
+
// ---- ownership ---------------------------------------------------------------------------------------------------
|
|
220
|
+
// uk_owned(n): n's module part is exactly a module of the run, or n's first segment is shared by an explicit dotted
|
|
221
|
+
// name. A module that merely ends with n's module part (`app.tasks` for `tasks.x`) does not own it: another service's
|
|
222
|
+
// worker may well have a top-level `tasks` module.
|
|
223
|
+
.decl uk_owned(n: symbol) cross_file
|
|
224
|
+
uk_owned(n) :- uk_name(n), split_dot(n, m, _), m != "", uk_module(m).
|
|
225
|
+
uk_owned(n) :- uk_name(n), split_dot(n, m, _), m != "", h = @head(n), uk_reg(x, "explicit"), x != h, @head(x) = h.
|
|
226
|
+
.decl uk_module(m: symbol)
|
|
227
|
+
uk_module(m) :- doc(_, _, m).
|
|
228
|
+
// uk_celery_own(n): Celery's own tasks (celery/app/builtins.py registers them as `celery.*`).
|
|
229
|
+
.decl uk_celery_own(n: symbol)
|
|
230
|
+
uk_celery_own(n) :- uk_name(n), @head(n) = "celery".
|
|
231
|
+
// uk_moved(n, q): a task whose def is named for n's last segment is registered as q. Each file states its tasks' def
|
|
232
|
+
// names and registered names (uk_task_def).
|
|
233
|
+
.decl uk_moved(n: symbol, q: symbol) cross_file
|
|
234
|
+
uk_moved(n, q) :- uk_name(n), split_dot(n, _, x), uk_task_def(x, q, nq, nk), uk_holds(nq, nk), q != n.
|
|
235
|
+
.decl uk_task_def(x: symbol, q: symbol, nq: symbol, nk: symbol)
|
|
236
|
+
uk_task_def(x, q, nq, nk) :- cel_task(f, nq, nk), def_name(f, x), cel_task_name(f, q, nq, nk).
|
|
237
|
+
|
|
238
|
+
// The cases, `upstream/celery-practice/authored/celery-practice-unknown-task-name/`: one repository in which each line
|
|
239
|
+
// ending in `# caught` is reported and no other line.
|
|
240
|
+
.test cases exactly
|
|
241
|
+
.fixture "proj/__init__.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/__init__.py"
|
|
242
|
+
.fixture "proj/celery.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/celery.py"
|
|
243
|
+
.fixture "proj/classes.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/classes.py"
|
|
244
|
+
.fixture "proj/client.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/client.py"
|
|
245
|
+
.fixture "proj/contract.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/contract.py"
|
|
246
|
+
.fixture "proj/factory.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/factory.py"
|
|
247
|
+
.fixture "proj/jobs.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/jobs.py"
|
|
248
|
+
.fixture "proj/maintenance.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/maintenance.py"
|
|
249
|
+
.fixture "proj/metrics.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/metrics.py"
|
|
250
|
+
.fixture "proj/schedule.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/schedule.py"
|
|
251
|
+
.fixture "proj/settings.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/settings.py"
|
|
252
|
+
.fixture "proj/tasks.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/tasks.py"
|
|
253
|
+
.fixture "proj/tests/__init__.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/tests/__init__.py"
|
|
254
|
+
.fixture "proj/tests/test_beat.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/tests/test_beat.py"
|
|
255
|
+
.fixture "proj/web/__init__.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/web/__init__.py"
|
|
256
|
+
.fixture "proj/web/views.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/web/views.py"
|
|
257
|
+
.fixture "proj/worker.py" from "../upstream/celery-practice/authored/celery-practice-unknown-task-name/proj/worker.py"
|
|
258
|
+
.expect _ at "proj/celery.py":10
|
|
259
|
+
.expect _ at "proj/celery.py":11
|
|
260
|
+
.expect _ at "proj/celery.py":19
|
|
261
|
+
.expect _ at "proj/celery.py":23
|
|
262
|
+
.expect _ at "proj/celery.py":35
|
|
263
|
+
.expect _ at "proj/celery.py":73
|
|
264
|
+
.expect _ at "proj/celery.py":80
|
|
265
|
+
.expect _ at "proj/celery.py":91
|
|
266
|
+
.expect _ at "proj/celery.py":94
|
|
267
|
+
.expect _ at "proj/classes.py":14
|
|
268
|
+
.expect _ at "proj/client.py":23
|
|
269
|
+
.expect _ at "proj/client.py":24
|
|
270
|
+
.expect _ at "proj/schedule.py":8
|
|
271
|
+
.expect _ at "proj/schedule.py":16
|
|
272
|
+
.expect _ at "proj/settings.py":4
|
|
273
|
+
.expect _ at "proj/web/views.py":14
|
|
274
|
+
.expect _ at "proj/web/views.py":15
|
|
275
|
+
.expect _ at "proj/web/views.py":16
|
|
276
|
+
.expect _ at "proj/web/views.py":22
|
|
277
|
+
.expect _ at "proj/web/views.py":24
|
|
278
|
+
.expect _ at "proj/web/views.py":28
|
|
279
|
+
.expect _ at "proj/web/views.py":29
|
|
280
|
+
.expect _ at "proj/web/views.py":33
|
|
281
|
+
.end
|