Skip to content

Commit

Permalink
(feat) #228 - Change AECU cloud startup hook to use sling job for pro…
Browse files Browse the repository at this point in the history
…cessing scripts
  • Loading branch information
christinebaumann committed May 7, 2024
1 parent 6cb15f3 commit 51d8efb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.jcr.Session;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class AecuCloudStartupService {
@Reference
private ServiceComponentRuntime serviceComponentRuntime;

@Reference
private JobManager jobManager;

private BundleContext bundleContext;

@Activate
Expand Down Expand Up @@ -170,13 +174,7 @@ private boolean servicesAreOk() {
* Starts the AECU migration
*/
void startAecuMigration() {
try {
LOGGER.info("AECU migration started");
aecuService.executeWithInstallHookHistory(AecuService.AECU_APPS_PATH_PREFIX);
LOGGER.info("AECU migration finished");
} catch (AecuException ae) {
LOGGER.error("Error while executing AECU migration", ae);
}
jobManager.addJob(AecuStartupJobConsumer.JOB_TOPIC, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.valtech.aecu.startuphook;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.HistoryEntry;

import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;


@Component(service=JobConsumer.class, property= {
JobConsumer.PROPERTY_TOPICS + "=" + AecuStartupJobConsumer.JOB_TOPIC
})
public class AecuStartupJobConsumer implements JobConsumer {

protected static final String JOB_TOPIC = "de/valtech/aecu/cloud/AecuStartupJobTopic";

private static final Logger LOGGER = LoggerFactory.getLogger(AecuStartupJobConsumer.class);

@Reference
private AecuService aecuService;


public JobResult process(final Job job) {
try {
LOGGER.info("AECU migration started");
HistoryEntry result = aecuService.executeWithInstallHookHistory(AecuService.AECU_APPS_PATH_PREFIX);
LOGGER.info("AECU migration finished with result "+result.getResult());
return JobResult.OK;
} catch (AecuException ae) {
LOGGER.error("Error while executing AECU migration", ae);
// Do not retry job, hence status CANCEL (=failed permanently) and not FAILED (=can be retried)
return JobResult.CANCEL;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"

queue.name="AECU Cloud Startup Job Queue"
queue.priority="NORM"
queue.topics="de/valtech/aecu/cloud/AecuStartupJobTopic"
queue.type="ORDERED"
queue.keepJobs="true"
/>

0 comments on commit 51d8efb

Please sign in to comment.