Skip to content

Commit fb75a18

Browse files
committed
supervisor: add --ignore-needs-attention
During development, we may want to run the supervisor against issues or errata that have been flagged for human attention. This change adds a command-line option to allow that.
1 parent 54b7dd9 commit fb75a18

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ else
187187
DRY_RUN_FLAG :=
188188
endif
189189

190+
IGNORE_NEEDS_ATTENTION_LOWER := $(shell echo $(IGNORE_NEEDS_ATTENTION) | tr '[:upper:]' '[:lower:]')
191+
ifeq ($(IGNORE_NEEDS_ATTENTION_LOWER),true)
192+
IGNORE_NEEDS_ATTENTION_FLAG := --ignore-needs-attention
193+
else
194+
IGNORE_NEEDS_ATTENTION_FLAG :=
195+
endif
196+
190197
.PHONY: supervisor-clear-queue
191198
supervisor-clear-queue:
192199
$(COMPOSE_SUPERVISOR) run --rm \
@@ -200,12 +207,12 @@ supervisor-collect:
200207
.PHONY: process-issue
201208
process-issue:
202209
$(COMPOSE_SUPERVISOR) run --rm \
203-
supervisor python -m supervisor.main $(DEBUG_FLAG) $(DRY_RUN_FLAG) process-issue $(JIRA_ISSUE)
210+
supervisor python -m supervisor.main $(DEBUG_FLAG) $(IGNORE_NEEDS_ATTENTION_FLAG) $(DRY_RUN_FLAG) process-issue $(JIRA_ISSUE)
204211

205212
.PHONY: process-erratum
206213
process-erratum:
207214
$(COMPOSE_SUPERVISOR) run --rm \
208-
supervisor python -m supervisor.main $(DEBUG_FLAG) $(DRY_RUN_FLAG) process-erratum $(ERRATA_ID)
215+
supervisor python -m supervisor.main $(DEBUG_FLAG) $(IGNORE_NEEDS_ATTENTION_FLAG) $(DRY_RUN_FLAG) process-erratum $(ERRATA_ID)
209216

210217

211218
# Common utility targets

supervisor/erratum_handler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class ErratumHandler(WorkItemHandler):
7979
adding comments, or flagging it for human attention.
8080
"""
8181

82-
def __init__(self, erratum: Erratum, *, dry_run: bool):
83-
super().__init__(dry_run=dry_run)
82+
def __init__(
83+
self, erratum: Erratum, *, dry_run: bool, ignore_needs_attention: bool
84+
):
85+
super().__init__(dry_run=dry_run, ignore_needs_attention=ignore_needs_attention)
8486
self.erratum = erratum
8587

8688
def resolve_flag_attention(self, why: str):
@@ -183,7 +185,7 @@ async def run(self) -> WorkflowResult:
183185
erratum.full_advisory,
184186
)
185187

186-
if erratum_needs_attention(erratum.id):
188+
if (not self.ignore_needs_attention) and erratum_needs_attention(erratum.id):
187189
return self.resolve_remove_work_item(
188190
"Erratum already flagged for human attention"
189191
)

supervisor/issue_handler.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class IssueHandler(WorkItemHandler):
2727
This includes changing the issue status, adding comments, and adding labels.
2828
"""
2929

30-
def __init__(self, issue: FullIssue, *, dry_run: bool):
31-
super().__init__(dry_run=dry_run)
30+
def __init__(
31+
self, issue: FullIssue, *, dry_run: bool, ignore_needs_attention: bool
32+
):
33+
super().__init__(dry_run=dry_run, ignore_needs_attention=ignore_needs_attention)
3234
self.issue = issue
3335

3436
def resolve_set_status(self, status: IssueStatus, why: str):
@@ -225,7 +227,10 @@ async def run(self) -> WorkflowResult:
225227

226228
logger.info("Running workflow for issue %s", issue.url)
227229

228-
if JiraLabels.NEEDS_ATTENTION.value in issue.labels:
230+
if (
231+
JiraLabels.NEEDS_ATTENTION.value in issue.labels
232+
and not self.ignore_needs_attention
233+
):
229234
return self.resolve_remove_work_item(
230235
"Issue has the jotnar_needs_attention label"
231236
)

supervisor/main.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@dataclass
2828
class State:
2929
dry_run: bool = False
30+
ignore_needs_attention: bool = False
3031

3132

3233
app_state = State()
@@ -108,7 +109,11 @@ async def process_once(queue: WorkQueue):
108109

109110
if work_item.item_type == WorkItemType.PROCESS_ISSUE:
110111
issue = get_issue(work_item.item_data, full=True)
111-
result = await IssueHandler(issue, dry_run=app_state.dry_run).run()
112+
result = await IssueHandler(
113+
issue,
114+
dry_run=app_state.dry_run,
115+
ignore_needs_attention=app_state.ignore_needs_attention,
116+
).run()
112117
if result.reschedule_in >= 0:
113118
await queue.schedule_work_items([work_item], delay=result.reschedule_in)
114119
else:
@@ -122,7 +127,11 @@ async def process_once(queue: WorkQueue):
122127
)
123128
elif work_item.item_type == WorkItemType.PROCESS_ERRATUM:
124129
erratum = get_erratum(work_item.item_data)
125-
result = await ErratumHandler(erratum, dry_run=app_state.dry_run).run()
130+
result = await ErratumHandler(
131+
erratum,
132+
dry_run=app_state.dry_run,
133+
ignore_needs_attention=app_state.ignore_needs_attention,
134+
).run()
126135
if result.reschedule_in >= 0:
127136
await queue.schedule_work_items([work_item], delay=result.reschedule_in)
128137
else:
@@ -163,7 +172,11 @@ async def do_process_issue(key: str):
163172
await init_kerberos_ticket()
164173

165174
issue = get_issue(key, full=True)
166-
result = await IssueHandler(issue, dry_run=app_state.dry_run).run()
175+
result = await IssueHandler(
176+
issue,
177+
dry_run=app_state.dry_run,
178+
ignore_needs_attention=app_state.ignore_needs_attention,
179+
).run()
167180
logger.info(
168181
"Issue %s processed, status=%s, reschedule_in=%s",
169182
key,
@@ -197,7 +210,11 @@ async def do_process_erratum(id: str):
197210
await init_kerberos_ticket()
198211

199212
erratum = get_erratum(id)
200-
result = await ErratumHandler(erratum, dry_run=app_state.dry_run).run()
213+
result = await ErratumHandler(
214+
erratum,
215+
dry_run=app_state.dry_run,
216+
ignore_needs_attention=app_state.ignore_needs_attention,
217+
).run()
201218

202219
logger.info(
203220
"Erratum %s (%s) processed, status=%s, reschedule_in=%s",
@@ -228,8 +245,9 @@ def process_erratum(id_or_url: str):
228245
@app.callback()
229246
def main(
230247
debug: bool = typer.Option(False, help="Enable debug mode."),
231-
dry_run: bool = typer.Option(
232-
False, "--dry-run", help="Don't actually change anything."
248+
dry_run: bool = typer.Option(False, help="Don't actually change anything."),
249+
ignore_needs_attention: bool = typer.Option(
250+
False, help="Process issues or errata flagged with jotnar_needs_attention."
233251
),
234252
):
235253
if debug:
@@ -240,6 +258,7 @@ def main(
240258
logging.basicConfig(level=logging.INFO)
241259

242260
app_state.dry_run = dry_run
261+
app_state.ignore_needs_attention = ignore_needs_attention
243262

244263
collector_endpoint = os.environ.get("COLLECTOR_ENDPOINT")
245264
if collector_endpoint is not None:

supervisor/work_item_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010

1111
class WorkItemHandler(ABC):
12-
def __init__(self, dry_run: bool = False):
12+
def __init__(self, dry_run: bool = False, ignore_needs_attention: bool = False):
1313
self.dry_run = dry_run
14+
self.ignore_needs_attention = ignore_needs_attention
1415

1516
def resolve_remove_work_item(self, why: str):
1617
return WorkflowResult(status=why, reschedule_in=-1)

0 commit comments

Comments
 (0)