Skip to content

[cron] full implementation #382

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Wandalen
Copy link
Contributor

No description provided.

@Wandalen
Copy link
Contributor Author

@jgarzik please, review, sir

@jgarzik jgarzik added the enhancement New feature or request label Apr 2, 2025
@jgarzik jgarzik requested a review from Copilot April 2, 2025 21:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements full cron functionality including command-line binaries, a cron job scheduler library, and comprehensive tests for both crontab and crond.

  • Added integration tests for crontab and crond commands
  • Implemented the cron job parsing, scheduling, and execution logic in the job module
  • Updated the Cargo workspace configuration to include the new cron package

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cron/tests/crontab_test.rs Added tests ensuring crontab command returns error status
cron/tests/crond_test.rs Added tests for crond command, including edge cases
cron/src/main.rs Minimal main function for the cron package
cron/src/lib.rs Exports the job module
cron/src/job.rs Implements cron job parsing, scheduling, and execution
cron/Cargo.toml Configures binaries and the library for the cron package
Cargo.toml Updates workspace settings to include cron
Comments suppressed due to low confidence (1)

cron/src/job.rs:223

  • [nitpick] Remove the debug print statement in next_execution to avoid exposing internal state in production.
println!("{:?}", monthdays.to_vec());

cron/src/job.rs Outdated

fn merge(self, other: Self) -> Self {
let mut a = self.to_vec();
let b = self.to_vec();
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

The merge function is incorrectly using self.to_vec() twice; replace the second occurrence with other.to_vec() to merge distinct sets.

Suggested change
let b = self.to_vec();
let b = other.to_vec();

Copilot uses AI. Check for mistakes.

cron/src/job.rs Outdated
.iter()
.filter(|x| x.next_execution(&now).is_some())
.min_by_key(|x| {
println!("{x:?}");
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

[nitpick] There is an unintended debug print in nearest_job that may clutter production logs; consider removing it.

Suggested change
println!("{x:?}");

Copilot uses AI. Check for mistakes.

cron/Cargo.toml Outdated
path = "src/bin/crond.rs"

[[bin]]
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

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

There should not be a binary called "main", just crontab and crond

.fold(Database(vec![]), |acc, next| acc.merge(next)))
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs signal handling

@Wandalen
Copy link
Contributor Author

@jgarzik fixed. Let me know if there is anything else you want to improve?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants