HI !
i have a problem that ive been trying to solve in my mind but its appears to be a little bit problematic.
the problem is that i need to created a workflow that will process some data from content fragments via payload and then that data will be use to launch multiple jobs/event with a different time, lets say for example that we have : cf = contentFragment
cfa - cron expre 1 = x | cron expre 2 = y
cfb - cron expre 1 = d | cron expre 2 = c
cfb - cron expre 1 = s | cron expre 2 = a
this three cf will be processed via payload path in the workflow custom step process, all of the cf will have two different cron expression that will represent the date when a property is gonna be published and the date when that property is gonna be unpublished. all those cron expressions can be different.
now thats the problem but for my solution i this steps :
now my problem comes in the third step, as by using this
List<Cf> propertyListRetrieveFromPropertiesInJobProperties;
for (Cf object : propertyListRetrieveFromPropertiesInJobProperties) {
map = may with properties take from the Cf object
scheduler.scheduler(this,map)
}
now this solution is not working as the jobs are not starting or doing anything when the time in cron express happens.
can someone advise me on how to do this ? my main problem is that i am not being able to see how to connect the workflowProcess and make that workflowProcess to launch the multiple jobs.
thanks in advance and any help will be greatly appreciated
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @workflownoob,
If I understand your case correctly, I think you should rather use scheduled jobs instead scheduler. I did a quick test, and was able to successfully create scheduled job from workflow process. The job was executed at given/scheduled time and was handled/consumed by dedicated job consumer. So your concept will change to this:
From implementation point of view you will have something like this:
Workflow process
@Component(
service = WorkflowProcess.class,
property = "process.label=CustomWorkflowProcess"
)
public class CustomWorkflowProcess implements WorkflowProcess {
@Reference
private JobManager jobManager;
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
Map properties = // map with props you would like to pass to JobConsumer
// depending on how would you like to schedule your job you can use different options than cron
String cron = // cron expresssion
createScheduldedJob(properties, cron);
}
private void createScheduldedJob(Map<String, Object> properties, String cron) {
JobBuilder jobBuilder = jobManager.createJob("custom/topic");
JobBuilder.ScheduleBuilder scheduleBuilder = jobBuilder.properties(properties).schedule();
// you can also use other methods like at to schedule single execution for given date
scheduleBuilder.cron(cron);
if (scheduleBuilder.add() == null) {
// error logging in case creation of scheduled job failed
}
}
}
Job consumer
@Component(
immediate = true,
service = JobConsumer.class,
property = {
JobConsumer.PROPERTY_TOPICS + "=custom/topic"
}
)
public class CustomJobConsumer implements JobConsumer {
@Override
public JobResult process(Job job) {
// do some processing
return JobResult.OK;
}
}
You can read more about sling jobs options under:
Hi,
Can you check the jobs/topic at http://localhost:4502/system/console/slingevent
Check this article for creating a sling job https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html
Custom topic can be created and used like
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ReplicationListener.java
Hi @workflownoob,
If I understand your case correctly, I think you should rather use scheduled jobs instead scheduler. I did a quick test, and was able to successfully create scheduled job from workflow process. The job was executed at given/scheduled time and was handled/consumed by dedicated job consumer. So your concept will change to this:
From implementation point of view you will have something like this:
Workflow process
@Component(
service = WorkflowProcess.class,
property = "process.label=CustomWorkflowProcess"
)
public class CustomWorkflowProcess implements WorkflowProcess {
@Reference
private JobManager jobManager;
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
Map properties = // map with props you would like to pass to JobConsumer
// depending on how would you like to schedule your job you can use different options than cron
String cron = // cron expresssion
createScheduldedJob(properties, cron);
}
private void createScheduldedJob(Map<String, Object> properties, String cron) {
JobBuilder jobBuilder = jobManager.createJob("custom/topic");
JobBuilder.ScheduleBuilder scheduleBuilder = jobBuilder.properties(properties).schedule();
// you can also use other methods like at to schedule single execution for given date
scheduleBuilder.cron(cron);
if (scheduleBuilder.add() == null) {
// error logging in case creation of scheduled job failed
}
}
}
Job consumer
@Component(
immediate = true,
service = JobConsumer.class,
property = {
JobConsumer.PROPERTY_TOPICS + "=custom/topic"
}
)
public class CustomJobConsumer implements JobConsumer {
@Override
public JobResult process(Job job) {
// do some processing
return JobResult.OK;
}
}
You can read more about sling jobs options under:
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies