Skip to content

Commit 9e73738

Browse files
committed
added debug logs, fixed default schedule not respected
1 parent e5d1d48 commit 9e73738

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ registries:
44
age.min:
55
age.max:
66
revisions: 10
7-
schedule: 1/5 * * * * *
7+
schedule: 1/45 * * * * *
88
rule:
99
test:
1010
age.min: 30s

src/instance.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ pub struct Instance {
2828
client: Arc<Docker>
2929
}
3030

31-
const RULE_REGEX: &str = "rule.(?<name>[a-z]+)";
31+
const RULE_REGEX: &str = "rule\\.(?<name>[a-z]+)";
3232
const DEFAULT_RULE_REGEX: &str = "default";
3333
const POLICY_NAME_REGEX: &str = "(?<policy>[a-z\\.]+)";
3434
/// Per default the schedule is set to daily at midnight
35-
const DEFAULT_SCHEDULE: &str = "0 0 * * * * *";
35+
const DEFAULT_SCHEDULE: &str = "0 0 0 * * * *";
3636

3737
impl Instance {
3838
pub fn new(id: String, mut name: String, labels: HashMap<String, String>, networks: HashMap<String, EndpointSettings>, client: Arc<Docker>) -> Result<Self, Error> {
@@ -129,11 +129,11 @@ impl Instance {
129129
}
130130

131131
fn get_default_rule_pattern() -> Regex {
132-
Regex::new(format!("{NAME}.{DEFAULT_RULE_REGEX}.{POLICY_NAME_REGEX}").as_str()).expect("Default rule pattern should be valid")
132+
Regex::new(format!("{NAME}\\.{DEFAULT_RULE_REGEX}\\.{POLICY_NAME_REGEX}").as_str()).expect("Default rule pattern should be valid")
133133
}
134134

135135
fn get_rule_pattern() -> Regex {
136-
Regex::new(format!("{NAME}.{RULE_REGEX}.{POLICY_NAME_REGEX}").as_str()).expect("Rule pattern should be valid")
136+
Regex::new(format!("{NAME}\\.{RULE_REGEX}\\.{POLICY_NAME_REGEX}").as_str()).expect("Rule pattern should be valid")
137137
}
138138

139139
/// Parse all rules including the default rule from the instance configuration
@@ -167,23 +167,29 @@ impl Instance {
167167
entry.push((key, value.as_str()))
168168
});
169169

170+
debug!("Rule labels {rule_labels:?}");
170171

171172
for (name, labels) in rule_labels {
172173
let is_default = default_rule_name.eq(&name);
173174
let rule = parse_rule(name.clone(), labels);
175+
debug!("Parsed rule {rule:?} default? {is_default}");
174176
if let Some(rule) = rule {
175177
if is_default {
176178
default_rule.tag_policies.extend(rule.tag_policies);
177179
default_rule.repository_policies.extend(rule.repository_policies);
178-
if default_rule.schedule.is_empty() {
180+
if rule.schedule.is_empty() {
179181
default_rule.schedule = default_schedule.clone();
182+
} else {
183+
default_rule.schedule = rule.schedule;
180184
}
181185
} else {
182186
rules.insert(name, rule);
183187
}
184188
}
185189
}
186190

191+
debug!("Default rule {default_rule:?}");
192+
187193
(default_rule, rules)
188194
}
189195

@@ -207,6 +213,7 @@ impl Instance {
207213
/// All tags (on repositories) which match at least one of the rules will be deleted and
208214
/// additionally the garbage collector inside the registry will be run automatically
209215
pub async fn apply_rules(&self, rules: Vec<String>) -> Result<(), Error> {
216+
debug!("Applying rules to registry '{}'", self.name);
210217
let distribution = Distribution::new(Arc::new(self.distribution.clone()));
211218
let repositories = distribution.get_repositories().await?;
212219

src/task.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ impl Task {
2626
let mut sched = JobScheduler::new().await.map_err(|err| Error::TaskCreationFailed(name.clone(), err.to_string()))?;
2727

2828
for (cron, rules) in bundles {
29+
debug!("Cron '{cron}' with rules '{}'", rules.join(", "));
2930
let instance = instance.clone();
3031
let copy_name = copy_name.clone();
31-
let job = Job::new_async(cron.as_str(), move |_uuid, _l| {
32+
let job = Job::new_async(cron.as_str(), move |_uuid, mut _l| {
3233
let instance = instance.clone();
3334
let rules = rules.clone();
3435
let name = copy_name.clone();
36+
3537
Box::pin(async move {
38+
let next_tick = _l.next_tick_for_job(_uuid).await;
39+
debug!("Next tick for registry '{name}' is {:?}", next_tick.unwrap_or_default().unwrap_or_default());
3640
info!("Applying rules '{}' to registry '{name}'", rules.join(", "));
3741
match instance.apply_rules(rules.clone()).await {
3842
Ok(_) => info!("Successfully applied rules '{}' to registry '{name}'", rules.join(", ")),

test-docker-compose.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ services:
99
- '5000:5000'
1010
labels:
1111
abwart.enable: true
12-
abwart.rule.test.revisions: 2
13-
abwart.rule.test.schedule: 1/30 * * * * *
12+
# abwart.rule.test.revisions: 2
13+
# abwart.rule.test.schedule: 1/30 * * * * *
1414
abwart.default.revisions: 10
15-
abwart.default.schedule: 0 2 * * * *
15+
abwart.default.schedule: 1/30 * * * * *
1616
abwart.network: test
1717
networks:
1818
- test
1919

2020
abwart:
21+
environment:
22+
RUST_LOG: debug
2123
build:
2224
dockerfile: Dockerfile
2325
volumes:

0 commit comments

Comments
 (0)