Skip to content

feat: add property-based job disable gate in runner#1897

Merged
moshloop merged 1 commit intomainfrom
aditya/job-disable-property
Apr 17, 2026
Merged

feat: add property-based job disable gate in runner#1897
moshloop merged 1 commit intomainfrom
aditya/job-disable-property

Conversation

@adityathebe
Copy link
Copy Markdown
Member

@adityathebe adityathebe commented Apr 17, 2026

  • Adds jobs..disable / jobs..disabled handling in job.Run()\n- Disabled jobs return before execution and before history start

Summary by CodeRabbit

Release Notes

  • New Features

    • Jobs can now be disabled at runtime using context properties. Setting a disable or disabled flag for a job prevents execution and skips all startup and initialization procedures.
  • Tests

    • Added comprehensive test coverage to verify that disabled jobs are properly handled, confirming no execution occurs and no history entries are created.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2026

Warning

Rate limit exceeded

@adityathebe has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 2 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 57 minutes and 2 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c0edf69-4313-4cc2-a611-27785c8a0ca8

📥 Commits

Reviewing files that changed from the base of the PR and between 1a2f05e and a1c0fda.

📒 Files selected for processing (2)
  • job/job.go
  • tests/job_test.go

Walkthrough

The Job.Run() method now includes an early-disable check that evaluates job properties for "disable" or "disabled" keys after initialization. If either property is set, the job logs the disabled state and returns without executing.

Changes

Cohort / File(s) Summary
Job Disable Logic
job/job.go
Added early-disable check in Job.Run() that evaluates job properties for "disable" or "disabled" keys and exits before starting the job if either is found.
Disable Verification Test
tests/job_test.go
Added test case verifying that jobs with disable properties set do not execute and produce no history entries.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a property-based disable gate for jobs in the runner.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aditya/job-disable-property
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch aditya/job-disable-property

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

Benchstat (Other)

Base: 148cf20a1ccbd81e7fa6ef001c6f0fc6032a6af0
Head: a1c0fda9395e84de43df07c4bcd656281b8598cd

📊 2 minor regression(s) (all within 5% threshold)

Benchmark Base Head Change p-value
ResourceSelectorQueryBuild/name_and_type-4 63.06µ 64.01µ +1.52% 0.026
ResourceSelectorQueryBuild/tags-4 17.31µ 17.38µ +0.39% 0.041
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/duty/bench
cpu: AMD EPYC 7763 64-Core Processor                
                                                       │ bench-base.txt │           bench-head.txt           │
                                                       │     sec/op     │    sec/op     vs base              │
InsertionForRowsWithAliases/external_users.aliases-4        564.6µ ± 5%   562.9µ ±  7%       ~ (p=0.699 n=6)
InsertionForRowsWithAliases/config_items.external_id-4      1.083m ± 9%   1.069m ± 11%       ~ (p=0.937 n=6)
ResourceSelectorConfigs/name-4                              215.1µ ± 3%   218.2µ ±  3%       ~ (p=0.180 n=6)
ResourceSelectorConfigs/name_and_type-4                     233.5µ ± 5%   240.3µ ±  3%       ~ (p=0.394 n=6)
ResourceSelectorConfigs/tags-4                              29.16m ± 5%   30.22m ±  3%       ~ (p=0.180 n=6)
ResourceSelectorQueryBuild/name-4                           42.93µ ± 1%   43.45µ ±  2%       ~ (p=0.065 n=6)
ResourceSelectorQueryBuild/name_and_type-4                  63.06µ ± 1%   64.01µ ±  1%  +1.52% (p=0.026 n=6)
ResourceSelectorQueryBuild/tags-4                           17.31µ ± 0%   17.38µ ±  0%  +0.39% (p=0.041 n=6)
geomean                                                     283.7µ        287.0µ        +1.18%

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

Benchstat (RLS)

Base: 148cf20a1ccbd81e7fa6ef001c6f0fc6032a6af0
Head: a1c0fda9395e84de43df07c4bcd656281b8598cd

📊 4 minor regression(s) (all within 5% threshold)

Benchmark Base Head Change p-value
RLS/Sample-15000/change_types/Without_RLS-4 4.571m 4.650m +1.73% 0.002
RLS/Sample-15000/configs/With_RLS-4 110.4m 111.4m +0.92% 0.026
RLS/Sample-15000/config_summary/With_RLS-4 661.9m 667.5m +0.84% 0.026
RLS/Sample-15000/analysis_types/Without_RLS-4 3.413m 3.438m +0.72% 0.026
✅ 4 improvement(s)
Benchmark Base Head Change p-value
RLS/Sample-15000/config_names/With_RLS-4 115.3m 112.3m -2.61% 0.002
RLS/Sample-15000/config_names/Without_RLS-4 10.56m 10.43m -1.23% 0.015
RLS/Sample-15000/config_changes/With_RLS-4 116.7m 115.4m -1.06% 0.002
RLS/Sample-15000/catalog_changes/With_RLS-4 116.7m 115.5m -0.98% 0.026
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/duty/bench
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
                                               │ bench-base.txt │          bench-head.txt           │
                                               │     sec/op     │   sec/op     vs base              │
RLS/Sample-15000/catalog_changes/Without_RLS-4      4.572m ± 1%   4.537m ± 1%       ~ (p=0.699 n=6)
RLS/Sample-15000/catalog_changes/With_RLS-4         116.7m ± 1%   115.5m ± 1%  -0.98% (p=0.026 n=6)
RLS/Sample-15000/config_changes/Without_RLS-4       4.554m ± 2%   4.541m ± 1%       ~ (p=0.180 n=6)
RLS/Sample-15000/config_changes/With_RLS-4          116.7m ± 0%   115.4m ± 1%  -1.06% (p=0.002 n=6)
RLS/Sample-15000/config_detail/Without_RLS-4        3.385m ± 2%   3.384m ± 0%       ~ (p=0.589 n=6)
RLS/Sample-15000/config_detail/With_RLS-4           111.3m ± 0%   111.7m ± 0%       ~ (p=0.065 n=6)
RLS/Sample-15000/config_names/Without_RLS-4         10.56m ± 1%   10.43m ± 1%  -1.23% (p=0.015 n=6)
RLS/Sample-15000/config_names/With_RLS-4            115.3m ± 0%   112.3m ± 1%  -2.61% (p=0.002 n=6)
RLS/Sample-15000/config_summary/Without_RLS-4       52.37m ± 1%   52.06m ± 1%       ~ (p=0.132 n=6)
RLS/Sample-15000/config_summary/With_RLS-4          661.9m ± 1%   667.5m ± 1%  +0.84% (p=0.026 n=6)
RLS/Sample-15000/configs/Without_RLS-4              5.870m ± 1%   5.891m ± 1%       ~ (p=0.065 n=6)
RLS/Sample-15000/configs/With_RLS-4                 110.4m ± 1%   111.4m ± 1%  +0.92% (p=0.026 n=6)
RLS/Sample-15000/analysis_types/Without_RLS-4       3.413m ± 1%   3.438m ± 1%  +0.72% (p=0.026 n=6)
RLS/Sample-15000/analysis_types/With_RLS-4          3.430m ± 1%   3.426m ± 0%       ~ (p=0.093 n=6)
RLS/Sample-15000/analyzer_types/Without_RLS-4       3.296m ± 1%   3.288m ± 2%       ~ (p=1.000 n=6)
RLS/Sample-15000/analyzer_types/With_RLS-4          3.315m ± 2%   3.309m ± 3%       ~ (p=0.394 n=6)
RLS/Sample-15000/change_types/Without_RLS-4         4.571m ± 1%   4.650m ± 1%  +1.73% (p=0.002 n=6)
RLS/Sample-15000/change_types/With_RLS-4            4.620m ± 2%   4.648m ± 2%       ~ (p=0.485 n=6)
RLS/Sample-15000/config_classes/Without_RLS-4       2.917m ± 1%   2.915m ± 1%       ~ (p=1.000 n=6)
RLS/Sample-15000/config_classes/With_RLS-4          111.3m ± 0%   111.7m ± 3%       ~ (p=0.065 n=6)
RLS/Sample-15000/config_types/Without_RLS-4         3.420m ± 1%   3.417m ± 1%       ~ (p=1.000 n=6)
RLS/Sample-15000/config_types/With_RLS-4            111.3m ± 0%   111.5m ± 0%       ~ (p=0.180 n=6)
geomean                                             16.86m        16.84m       -0.10%

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
job/job.go (2)

396-404: Disable gate runs after init() side effects.

j.init() starts the history evictor, populates the status ring from the DB, and mutates context/object metadata before the disable check. If the intent is to make a disabled job a true no-op, consider evaluating the disable properties prior to j.init() (the property keys don't depend on anything init sets). As-is, a disabled job still incurs DB work and evictor startup on the first call. Not a correctness bug since init() is idempotent via j.initialized.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@job/job.go` around lines 396 - 404, The disable-property check currently runs
after j.init(), causing initialization side effects (history evictor, DB reads)
even for disabled jobs; move the properties check (the j.Properties().On(false,
j.getPropertyNames("disable")...) || j.Properties().On(false,
j.getPropertyNames("disabled")...)) to run before calling j.init(), and only
call j.init() if the job is not disabled; keep the existing r.Failf("failed to
initialize job: %s", r.ID()) handling for init errors and preserve early returns
to avoid starting the evictor or touching the DB for disabled jobs.

401-404: Consider collapsing both property lookups into a single On() call.

Properties().On() accepts variadic keys and returns on first match, so both alias sets can be combined. This also avoids registering property metadata twice via newProp (see context/properties.go:77-99).

♻️ Suggested refactor
-	if j.Properties().On(false, j.getPropertyNames("disable")...) || j.Properties().On(false, j.getPropertyNames("disabled")...) {
-		ctx.Tracef("job disabled via properties")
-		return
-	}
+	disableKeys := append(j.getPropertyNames("disable"), j.getPropertyNames("disabled")...)
+	if j.Properties().On(false, disableKeys...) {
+		ctx.Tracef("job disabled via properties")
+		return
+	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@job/job.go` around lines 401 - 404, The two separate property checks should
be collapsed into a single call to Properties().On to avoid duplicate metadata
registration; replace the two calls to j.Properties().On(false,
j.getPropertyNames("disable")...) and j.Properties().On(false,
j.getPropertyNames("disabled")...) with one call that passes both key slices
(e.g. combine the results of j.getPropertyNames("disable") and
j.getPropertyNames("disabled") into a single variadic argument) while keeping
the same default false and preserving the ctx.Tracef("job disabled via
properties") return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@job/job.go`:
- Around line 396-404: The disable-property check currently runs after j.init(),
causing initialization side effects (history evictor, DB reads) even for
disabled jobs; move the properties check (the j.Properties().On(false,
j.getPropertyNames("disable")...) || j.Properties().On(false,
j.getPropertyNames("disabled")...)) to run before calling j.init(), and only
call j.init() if the job is not disabled; keep the existing r.Failf("failed to
initialize job: %s", r.ID()) handling for init errors and preserve early returns
to avoid starting the evictor or touching the DB for disabled jobs.
- Around line 401-404: The two separate property checks should be collapsed into
a single call to Properties().On to avoid duplicate metadata registration;
replace the two calls to j.Properties().On(false,
j.getPropertyNames("disable")...) and j.Properties().On(false,
j.getPropertyNames("disabled")...) with one call that passes both key slices
(e.g. combine the results of j.getPropertyNames("disable") and
j.getPropertyNames("disabled") into a single variadic argument) while keeping
the same default false and preserving the ctx.Tracef("job disabled via
properties") return behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ad28415-d8f1-4fb0-9afd-09dc5ea04114

📥 Commits

Reviewing files that changed from the base of the PR and between 148cf20 and 1a2f05e.

📒 Files selected for processing (2)
  • job/job.go
  • tests/job_test.go

@adityathebe adityathebe force-pushed the aditya/job-disable-property branch from 1a2f05e to a1c0fda Compare April 17, 2026 04:55
@moshloop moshloop merged commit b8ae2d6 into main Apr 17, 2026
19 checks passed
@moshloop moshloop deleted the aditya/job-disable-property branch April 17, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants