Skip to content

Commit f57d13e

Browse files
Better logging
1 parent 86d78d6 commit f57d13e

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

core/src/main/java/dev/vml/es/acm/core/script/AutomaticScriptScheduler.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ public void onChange(List<ResourceChange> changes) {
132132
}
133133

134134
private void bootWhenInstanceUp() {
135-
LOG.info("Automatic scripts booting on instance up");
135+
LOG.info("Automatic scripts booting on instance up - job scheduling");
136136
unscheduleBoot();
137137
scheduleBoot();
138+
LOG.info("Automatic scripts booting on instance up - job scheduled");
138139
}
139140

140141
private void bootWhenScriptsChanged() {
141-
LOG.info("Automatic scripts booting on script changes");
142+
LOG.info("Automatic scripts booting on script changes - job scheduling");
142143
unscheduleBoot();
143144
scheduleBoot();
145+
LOG.info("Automatic scripts booting on script changes - job scheduled");
144146
}
145147

146148
private void unscheduleBoot() {
@@ -168,13 +170,15 @@ private ScheduleResult determineSchedule(Script script, ResourceResolver resourc
168170

169171
private Job bootJob() {
170172
return context -> {
173+
LOG.info("Automatic scripts booting - job started");
171174
unscheduleScripts();
172175
if (awaitInstanceHealthy(
173176
"Automatic scripts queueing and scheduling",
174177
config.healthCheckRetryCountBoot(),
175178
config.healthCheckRetryInterval())) {
176179
queueAndScheduleScripts();
177180
}
181+
LOG.info("Automatic scripts booting - job finished");
178182
};
179183
}
180184

@@ -264,28 +268,28 @@ private void scheduleCronScript(Script script, CronSchedule schedule) {
264268

265269
private Job cronJob(String scriptPath) {
266270
return context -> {
267-
if (!awaitInstanceHealthy(
271+
LOG.info("Cron schedule script '{}' - job started", scriptPath);
272+
if (awaitInstanceHealthy(
268273
String.format("Cron schedule script '%s' queueing", scriptPath),
269274
config.healthCheckRetryCountCron(),
270275
config.healthCheckRetryInterval())) {
271-
return;
272-
}
273-
274-
try (ResourceResolver resourceResolver = ResolverUtils.contentResolver(resourceResolverFactory, null)) {
275-
ScriptRepository scriptRepository = new ScriptRepository(resourceResolver);
276-
Script script = scriptRepository.read(scriptPath).orElse(null);
277-
if (script == null) {
278-
LOG.error("Cron schedule script '{}' not found in repository!", scriptPath);
279-
} else {
280-
if (checkScript(script, resourceResolver)) {
281-
queueScript(script);
276+
try (ResourceResolver resourceResolver = ResolverUtils.contentResolver(resourceResolverFactory, null)) {
277+
ScriptRepository scriptRepository = new ScriptRepository(resourceResolver);
278+
Script script = scriptRepository.read(scriptPath).orElse(null);
279+
if (script == null) {
280+
LOG.error("Cron schedule script '{}' not found in repository!", scriptPath);
282281
} else {
283-
LOG.info("Cron schedule script '{}' not eligible for queueing!", scriptPath);
282+
if (checkScript(script, resourceResolver)) {
283+
queueScript(script);
284+
} else {
285+
LOG.info("Cron schedule script '{}' not eligible for queueing!", scriptPath);
286+
}
284287
}
288+
} catch (LoginException e) {
289+
LOG.error("Cannot access repository while queueing cron schedule script '{}'!", scriptPath, e);
285290
}
286-
} catch (LoginException e) {
287-
LOG.error("Cannot access repository while queueing cron schedule script '{}'!", scriptPath, e);
288291
}
292+
LOG.info("Cron schedule script '{}' - job finished", scriptPath);
289293
};
290294
}
291295

test/project/setup.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,25 @@ add_vendor_package() {
5959

6060
echo "Appending package '$groupId:$artifactId:$version' to '$all_pom'"
6161

62-
xml_append_block_if_missing "$all_pom" "$dep_marker_id" "<dependencies>" "$dep_block"
63-
xml_append_block_if_missing "$all_pom" "$emb_marker_id" "<embeddeds>" "$emb_block"
62+
xml_append_block_if_missing "$all_pom" "$dep_marker_id" "</dependencies>" "$dep_block"
63+
xml_append_block_if_missing "$all_pom" "$emb_marker_id" "</embeddeds>" "$emb_block"
6464
}
6565

6666
xml_append_block_if_missing() {
6767
local file="$1"
6868
local marker_id="$2"
69-
local insert_after="$3"
69+
local insert_before="$3"
7070
local block="$4"
7171
local marker="<!-- $marker_id -->"
7272
local found=0
7373

7474
if ! grep -q "$marker" "$file"; then
7575
while IFS= read -r line; do
76-
echo "$line"
77-
if [[ $found -eq 0 && "$line" == *"$insert_after"* ]]; then
78-
printf "%s\n%s\n" "$marker" "$block"
76+
if [[ $found -eq 0 && "$line" == *"$insert_before"* ]]; then
77+
printf "%s\n%s\n%s\n" "$marker" "$block" "$line"
7978
found=1
79+
else
80+
echo "$line"
8081
fi
8182
done < "$file" > "$file.tmp" && mv "$file.tmp" "$file"
8283
fi

0 commit comments

Comments
 (0)