Skip to content

Conversation

@1daidai1
Copy link
Collaborator

@1daidai1 1daidai1 commented Dec 17, 2025

Summary by CodeRabbit

  • New Features
    • Added --signal / -s flag to send a signal when time limits approach. Accepts signal names (with or without "SIG") or numeric values, with optional delay via @seconds (default: 60s).
    • Tasks/jobs now carry an optional signal parameter so the signal and delay are applied when scheduled.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Walkthrough

Adds a new CLI --signal/-s flag across calloc, cbatch, and crun; introduces signal parsing utilities and a new protobuf SignalParam; parses and attaches signal parameters to task/step messages before marshalling.

Changes

Cohort / File(s) Summary
Proto Definitions
protos/PublicDefs.proto
Adds SignalParam message (signal_number:int32, seconds_before_kill:uint32) and optional signal_param fields to TaskToCtld (tag 42) and StepToD (tag 30).
Utility Parsing
internal/util/string.go
Adds SignalMap and ParseSignalParamString(input string) (int32, uint32, error) to parse `signame
CLI Flag Registration
internal/calloc/cmd.go, internal/cbatch/cmd.go, internal/crun/cmd.go
Introduces FlagSignal string and registers --signal/-s with help: "send signal when time limit within time seconds, format: signum[@time]".
Main Flow Integration
internal/calloc/calloc.go, internal/cbatch/cbatch.go, internal/crun/crun.go
Parse FlagSignal via ParseSignalParamString; on success set SignalParam (SignalNumber, SecondsBeforeKill) on job/task/step messages; propagate parse errors as CLI/command errors.
sequenceDiagram
    participant CLI as CLI (calloc/cbatch/crun)
    participant Parser as util.ParseSignalParamString
    participant Builder as Job/Task Builder
    participant Proto as protobuf (TaskToCtld / StepToD)
    CLI->>Parser: pass FlagSignal string
    Parser-->>CLI: signalNumber, secondsBeforeKill / error
    CLI->>Builder: set SignalParam on job/task (SignalNumber, SecondsBeforeKill)
    Builder->>Proto: marshal job/task with optional signal_param
    Proto-->>Builder: marshalled payload
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Review ParseSignalParamString() edge cases (name resolution, prefix handling, numeric limits).
  • Confirm protobuf tag choices (42, 30) don't conflict.
  • Verify consistent error messages and flag wiring across calloc, cbatch, crun.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • L-Xiafeng
  • NamelessOIer

Poem

🐇 I parsed a flag beneath the moonlit sky,

SIG or 9 — I’ll count to sixty by,
A proto whisper, a task set free,
SignalParam hops on — and off goes the tree! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions only cbatch, but the changeset adds --signal support across multiple commands (calloc, cbatch, crun) and introduces shared utilities and proto definitions. Revise the title to reflect the broader scope, such as 'Add --signal flag support to cbatch, calloc, and crun commands' or 'Add signal parameter support to scheduling commands'.
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev/cbatchsignalnew

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.

@1daidai1 1daidai1 changed the title add cbatch signal Add cbatch --signal Dec 17, 2025
@1daidai1 1daidai1 force-pushed the dev/cbatchsignalnew branch from 85eafa4 to 2c22680 Compare December 17, 2025 06:41
Copy link
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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/cbatch/cbatch.go (1)

324-329: Missing CLI flag handling for --signal.

The FlagSignal is registered in cmd.go but never processed in the CLI flag handling section (lines 214-339). This means --signal passed on the command line won't take effect, only script directives will work.

Add this code after line 329 (after FlagHold handling):

 	if FlagHold {
 		task.Hold = true
 	}
+	if FlagSignal != "" {
+		sig, sec, err := util.ParseSignalParamString(FlagSignal)
+		if err != nil {
+			return nil, fmt.Errorf("invalid argument: invalid --signal value '%s': %w", FlagSignal, err)
+		}
+		task.SignalParam = &protos.SignalParam{
+			SignalNumber:      sig,
+			SecondsBeforeKill: sec,
+		}
+	}
 
 	// Set and check the extra attributes
🧹 Nitpick comments (2)
internal/util/string.go (2)

44-58: Consider expanding SignalMap or documenting the limited set.

The SignalMap includes only 13 signals. While these cover common use cases, users might expect support for additional signals like SIGSTOP, SIGCONT, SIGCHLD, etc.

Consider either:

  1. Expanding SignalMap to include all commonly-used signals
  2. Adding a comment documenting why only these signals are supported

1490-1491: Document the default 60-second timeout.

The default value of 60 seconds for secondsBeforeKill appears in two places but isn't documented. Consider adding a comment explaining why 60 seconds was chosen as the default.

Also applies to: 1502-1503

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06febd8 and 85eafa4.

📒 Files selected for processing (8)
  • internal/calloc/calloc.go (1 hunks)
  • internal/calloc/cmd.go (2 hunks)
  • internal/cbatch/cbatch.go (1 hunks)
  • internal/cbatch/cmd.go (2 hunks)
  • internal/crun/cmd.go (2 hunks)
  • internal/crun/crun.go (1 hunks)
  • internal/util/string.go (3 hunks)
  • protos/PublicDefs.proto (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
internal/crun/crun.go (5)
internal/calloc/cmd.go (1)
  • FlagSignal (54-54)
internal/cbatch/cmd.go (1)
  • FlagSignal (66-66)
internal/crun/cmd.go (1)
  • FlagSignal (67-67)
internal/util/string.go (1)
  • ParseSignalParamString (1457-1507)
internal/util/err.go (2)
  • NewCraneErr (60-65)
  • ErrorCmdArg (36-36)
internal/calloc/calloc.go (5)
internal/calloc/cmd.go (1)
  • FlagSignal (54-54)
internal/cbatch/cmd.go (1)
  • FlagSignal (66-66)
internal/crun/cmd.go (1)
  • FlagSignal (67-67)
internal/util/string.go (1)
  • ParseSignalParamString (1457-1507)
internal/util/err.go (2)
  • NewCraneErr (60-65)
  • ErrorCmdArg (36-36)
internal/calloc/cmd.go (1)
internal/crun/cmd.go (1)
  • FlagSignal (67-67)
internal/cbatch/cbatch.go (1)
internal/util/string.go (1)
  • ParseSignalParamString (1457-1507)
🪛 GitHub Actions: Go Code Quality Check
internal/crun/cmd.go

[error] 1-1: gofmt formatting check failed. File is not properly formatted. Run 'gofmt -w .' to fix formatting.

internal/util/string.go

[error] 1-1: gofmt formatting check failed. File is not properly formatted. Run 'gofmt -w .' to fix formatting.

🔇 Additional comments (6)
internal/calloc/cmd.go (1)

54-54: LGTM! Signal flag integration is clean.

The flag variable declaration and registration follow the established patterns in this codebase. The description text is clear and consistent with the format used in crun and cbatch.

Also applies to: 107-107

protos/PublicDefs.proto (1)

135-138: LGTM! Proto definitions are well-structured.

The SignalParam message definition is clean, and the optional fields are correctly added to both TaskToCtld and StepToD. Field tags (42 and 30) don't conflict with existing fields in the respective messages.

Also applies to: 188-188, 345-345

internal/crun/cmd.go (1)

67-67: LGTM! Flag registration is consistent.

The implementation follows the same pattern as calloc and cbatch.

Note: The pipeline indicates a gofmt formatting issue for this file. Please run gofmt -w internal/crun/cmd.go to fix.

Also applies to: 124-124

internal/calloc/calloc.go (1)

476-484: LGTM! Signal parameter handling is correct.

The implementation correctly parses the signal flag, handles errors appropriately, and initializes the SignalParam before marshalling extra attributes. This follows the established pattern used in other components.

internal/cbatch/cmd.go (1)

66-66: LGTM! Flag declaration and registration are consistent.

The implementation aligns with the patterns used in calloc and crun.

Note: The pipeline indicates a gofmt formatting issue. Please run gofmt -w internal/cbatch/cmd.go to fix.

Also applies to: 159-159

internal/cbatch/cbatch.go (1)

196-203: LGTM! Script-based signal parameter handling is correct.

The signal parameter is properly parsed from #CBATCH directives and assigned to task.SignalParam.

Copy link
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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/calloc/calloc.go (1)

476-484: Signal parameter parsing looks correct.

The implementation correctly parses the --signal flag, handles errors appropriately, and populates the SignalParam protobuf message. The error handling is consistent with other flag parsing in this file.

Optional: Consider using a composite literal for initialization.

Lines 481-483 can be simplified:

-		task.SignalParam = &protos.SignalParam{}
-		task.SignalParam.SignalNumber = sig
-		task.SignalParam.SecondsBeforeKill = sec
+		task.SignalParam = &protos.SignalParam{
+			SignalNumber:      sig,
+			SecondsBeforeKill: sec,
+		}

Note: cbatch does not implement signal parameter handling. The consistency check should only cover calloc and crun. Additionally, there's a minor inconsistency in error message formatting between them: crun includes a trailing period while calloc does not.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85eafa4 and 2c22680.

📒 Files selected for processing (8)
  • internal/calloc/calloc.go (1 hunks)
  • internal/calloc/cmd.go (2 hunks)
  • internal/cbatch/cbatch.go (1 hunks)
  • internal/cbatch/cmd.go (2 hunks)
  • internal/crun/cmd.go (2 hunks)
  • internal/crun/crun.go (1 hunks)
  • internal/util/string.go (3 hunks)
  • protos/PublicDefs.proto (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • internal/cbatch/cmd.go
  • internal/calloc/cmd.go
  • protos/PublicDefs.proto
  • internal/util/string.go
  • internal/crun/crun.go
  • internal/crun/cmd.go
  • internal/cbatch/cbatch.go
🧰 Additional context used
🧬 Code graph analysis (1)
internal/calloc/calloc.go (5)
internal/calloc/cmd.go (1)
  • FlagSignal (54-54)
internal/cbatch/cmd.go (1)
  • FlagSignal (66-66)
internal/crun/cmd.go (1)
  • FlagSignal (67-67)
internal/util/string.go (1)
  • ParseSignalParamString (1456-1506)
internal/util/err.go (2)
  • NewCraneErr (60-65)
  • ErrorCmdArg (36-36)

RootCmd.Flags().BoolVar(&FlagExclusive, "exclusive", false, "Exclusive node resources")
RootCmd.Flags().BoolVarP(&FlagHold, "hold", "H", false, "Hold the job until it is released")
RootCmd.Flags().StringVarP(&FlagLicenses, "licenses", "L", "", "Licenses used for the job")
RootCmd.Flags().StringVarP(&FlagSignal, "signal", "s", "", "send signal when time limit within time seconds, format: signum[@time]")
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个地方不支持 B/R 选项吗?

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.

3 participants