Job Consumer is not being triggered | Community
Skip to main content
Level 2
January 23, 2023
Solved

Job Consumer is not being triggered

  • January 23, 2023
  • 5 replies
  • 5363 views

I set up the job to be triggered daily and is not happening, I cannot see any on the logs that could be causing this issue, months ago we have the same job consumer working properly on AEM Cloud but now after we enable it I can see the job is set to trigger but the consumer is not happening any time 

 

Scheduling job : midnight/job/categories, hour 0 minute 10

 

@Component(service=JobConsumer.class,
immediate = true,
property= {
JobConsumer.PROPERTY_TOPICS + "=midnight/job/categories"
})
public class CategoriesConsumer implements JobConsumer {


{ "topic": "midnight/job/categories", "instances": [ "33f32c32-5bd5-4fcb-b2a2------------", "local" ] },

I can see the job has an instance assigned  but on crx 

So no idea why the consumer is not being triggered

 

Additional the scheduler is happening as I can see the logs 

Collection<ScheduledJobInfo> myJobs = jobManager.getScheduledJobs(TOPIC, 1, null);
log.info("Scheduler {} is enable {}",TOPIC,config.enabled());
if (myJobs.isEmpty()) {
// daily invocation not yet scheduled
log.info("Scheduling job : {}, hour {} minute {}", TOPIC, config.hour(),config.minute());
JobBuilder.ScheduleBuilder scheduleBuilder = jobManager.createJob(TOPIC).schedule();
scheduleBuilder.hourly(config.minute());
if (scheduleBuilder.add() == null) {
// something went wrong here, use scheduleBuilder.add(List<String>) instead to get further information about the error
log.debug("failed to add scheduler : {}, daily {} {}", TOPIC, config.hour(),config.minute());
}
}

@aditya_chabuku 

Regards

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by jonsan191086

Hi Everyone the issue was related to the parameters sent to the job I was not sending anything to the job so is not being executed

Map<String,Object> params = new HashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String date = sdf.format(Calendar.getInstance().getTime());
params.put("date", date);
jobManager.addJob(TOPIC,params);

After adding some parameters to the job topic the jobs being executed  

5 replies

Aditya_Chabuku
Community Advisor
Community Advisor
January 23, 2023

Hi @jonsan191086 ,

 Can you give a bit more details about the

use case & are you using any schedulers to do so.?

Thanks,Aditya Chabuku
Level 2
January 23, 2023

The scheduler is calling an external endpoint to create/update data (Content Fragments and Pages if required) 

Aditya_Chabuku
Community Advisor
Community Advisor
January 24, 2023

Hey @jonsan191086 , Scheduler seems fine, try Job Consumer class option i gave above.

 

Thanks,Aditya Chabuku
Adobe Employee
January 24, 2023
Aditya_Chabuku
Community Advisor
Community Advisor
January 24, 2023

Hey @jonsan191086 ,

 

I think It's an issue with Job Consumer Class, I found some useful code from Old Community Posts. 

package com.aem.demoproject.core.listeners; import org.apache.sling.event.jobs.Job; import org.apache.sling.event.jobs.JobManager; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; @Component public class JobComponent { @Reference private JobManager jobManager; public static final String JOB_TOPIC="com/sling/eventing/page/job"; private final Logger LOG = LoggerFactory.getLogger(this.getClass()); @Activate protected void activate(){ addJob(); } public void addJob(){ LOG.debug("Inside add job"); Map<String,Object> param = new HashMap<String,Object>(); param.put("eventPath","/content/demo"); Job job = jobManager.addJob(JOB_TOPIC,param); LOG.info("Job "+job.getTopic()+" is created successfully on "+job.getCreated().getTime()); } } JobConsumerImpl.java: package com.aem.demoproject.core.listeners; import org.apache.sling.event.jobs.Job; import org.apache.sling.event.jobs.consumer.JobConsumer; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component(service=JobConsumer.class, immediate = true, property = {JobConsumer.PROPERTY_TOPICS + "=" + JobComponent.JOB_TOPIC}) public class JobConsumerImpl implements JobConsumer { private final Logger LOG = LoggerFactory.getLogger(this.getClass()); @Override public JobResult process(Job job) { LOG.info("Inside job process method"); String eventPath = (String) job.getProperty("eventPath"); LOG.info("Event path={}", eventPath); return JobResult.OK; // Return based on actual implementation logic. } }

Hope this helps,

Aditya Chabuku

Thanks,Aditya Chabuku
Level 2
January 24, 2023

I have a consumer just for a test and the same case here never happens on the cloud if I tried on my local works fine 

@Component(service= JobConsumer.class,
immediate = true,
property= {
JobConsumer.PROPERTY_TOPICS + "=testing/job/jhon"
})
public class TestingConsumer implements JobConsumer {

private static final Logger log = LoggerFactory.getLogger(TestingConsumer.class);

public JobResult process(final Job job){
log.info("Testing Scheduler Consumer is now running");
log.info("Time {}", Calendar.getInstance().getTime());


return JobResult.OK;
}
}

 Also, I found some logs that maybe are related, as this is a cloud I'm not able to see if the bundle is being affected or how is this being affecting others bundles

[{"name": "All bundles are up", "pid": "org.apache.felix.hc.generalchecks.BundlesStartedCheck~systemready", "message": ["TEMPORARILY_UNAVAILABLE Inactive bundle 0 org.apache.felix.framework: STARTING, "INFO --- unsatisfied ref jobManager interface org.apache.sling.event.jobs.JobManager ","INFO --- Component org.apache.sling.event.impl.jobs.JobManagerImpl satisfied","INFO --- unsatisfied ref workflowBucketManager interface com.adobe.granite.workflow.core.jcr.WorkflowBucketManager ",

sravs
Community Advisor
Community Advisor
January 25, 2023

Hi @jonsan191086,

 

Can you please check whether the job topic is added under the "Apache Sling queue configuration".

Level 2
January 25, 2023

This is all I have access to on Cloud, sadly I cannot see the bundles or configurations as we see on previous versions of AEM 

I can see here there are no scheduled jobs but on local, I can see nodes on that node 

 

sravs
Community Advisor
Community Advisor
January 27, 2023

Can you please check the "Apache Sling queue Configuration" as I mentioned earlier? under configurations.

jonsan191086AuthorAccepted solution
Level 2
January 31, 2023

Hi Everyone the issue was related to the parameters sent to the job I was not sending anything to the job so is not being executed

Map<String,Object> params = new HashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String date = sdf.format(Calendar.getInstance().getTime());
params.put("date", date);
jobManager.addJob(TOPIC,params);

After adding some parameters to the job topic the jobs being executed