Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Job Consumer is not being triggered

Avatar

Level 2

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 

joathansanchezpublicis_0-1674490911386.png

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());
}
}

jonathansanchezpublicis_0-1674492113276.png

@Aditya_Chabuku 

Regards

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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  

View solution in original post

12 Replies

Avatar

Community Advisor

Hi @jonsan191086 ,

 Can you give a bit more details about the

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

Thanks,

Aditya Chabuku

Avatar

Level 2

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

Avatar

Community Advisor

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

 

Thanks,

Aditya Chabuku

Avatar

Community Advisor

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

Avatar

Level 2

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

jonathansanchezpublicis_0-1674598621257.png

[{"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 ",

Avatar

Level 4

Hi @jonsan191086,

 

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

sravs_0-1674646613681.png

Avatar

Level 2

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 

jonathansanchezpublicis_0-1674680404111.png

jonathansanchezpublicis_1-1674680645420.png

jonathansanchezpublicis_2-1674680684830.png

jonathansanchezpublicis_3-1674680721643.png

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

 

Avatar

Level 4

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

Avatar

Level 2

As I told you I don't have access to see that way the configurations only as json format and there is any called that way on AEM Cloud 

jonsan191086_0-1674858584442.png

jonsan191086_1-1674858635033.png

 

Avatar

Level 4

In AEM as a Cloud service, we can see the configurations or bundles either in text or in JSON. you need to search with the PID of the configurations. if you are unable to find the configuration you need to configure that and deploy to the instance.

Avatar

Correct answer by
Level 2

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