Scheduler created through archetype 19 doesn't seem to ever run OOTB

Avatar

Avatar

grantc99475970

Avatar

grantc99475970

grantc99475970

05-08-2019

Using AEM 6.5, I'm trying to create a Scheduler, similar to this: Adobe Experience Manager Help | Scheduling Adobe Experience Manager Jobs using Apache Sling
But these linked instructions appear to not work with 6.5.

So instead, I'm basing my scheduler off the archetype 19 available here: https://github.com/adobe/aem-project-archetype , however, I'm still having issues.

To create a new bundle, I run:

mvn archetype:generate -DarchetypeGroupId="com.adobe.granite.archetypes" -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=19

Then I add some logs to the SimpleScheduledTask.java that is created:

package test.core.schedulers;

import org.osgi.service.component.annotations.Activate;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.metatype.annotations.AttributeDefinition;

import org.osgi.service.metatype.annotations.Designate;

import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

/**

* A simple demo for cron-job like tasks that get executed regularly.

* It also demonstrates how property values can be set. Users can

* set the property values in /system/console/configMgr

*/

@Designate(ocd=SimpleScheduledTask.Config.class)

@Component(service=Runnable.class)

public class SimpleScheduledTask implements Runnable {

    @ObjectClassDefinition(name="A test scheduled task",

                           description = "Simple demo for cron-job like task with properties")

    public static @interface Config {

        @AttributeDefinition(name = "Cron-job expression")

        String scheduler_expression() default "*/30 * * * * ?";

        @AttributeDefinition(name = "Concurrent task",

                             description = "Whether or not to schedule this task concurrently")

        boolean scheduler_concurrent() default false;

        @AttributeDefinition(name = "A parameter",

                             description = "Can be configured in /system/console/configMgr")

        String myParameter() default "";

    }

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private String myParameter;

   

    @Override

    public void run() {

        System.out.println("running");

        logger.debug("SimpleScheduledTask is now running, myParameter='{}'", myParameter);

    }

    @Activate

    protected void activate(final Config config) {

        System.out.println("activating");

        myParameter = config.myParameter();

    }

}

Then I install this bundle using

mvn clean install -PautoInstallBundle

So now my bundle is installed:

And my service is configured:

1807686_pastedImage_14.png

And my stdout.log has the  "activating" log from the code, but I'm never seeing any "running" logs, nor am I seeing any evidence of errors in the error.log

So it appears to me that the archetype sample Schedule simply doesn't work out of the box (OOTB), unless I'm missing something.

How can I get this to work?

Here are the dependencies in the pom.xml where I ran the first mvn command:


Here

ependencyManagement>

          <dependencies>                <dependency>                     <groupId>biz.aQute</groupId>                     <artifactId>bndlib</artifactId>                     <version>1.50.0</version>                     <scope>provided</scope>                </dependency>                 <!-- Old OSGI Dependencies -->                <dependency>                     <groupId>org.osgi</groupId>                     <artifactId>org.osgi.compendium</artifactId>                     <version>4.2.0</version>                     <scope>provided</scope>                </dependency>                                                                <!-- OSGi Dependencies -->                <dependency>                     <groupId>org.osgi</groupId>                     <artifactId>osgi.core</artifactId>                     <version>6.0.0</version>                     <scope>provided</scope>                </dependency>                <dependency>                     <groupId>org.osgi</groupId>                     <artifactId>osgi.cmpn</artifactId>                     <version>6.0.0</version>                     <scope>provided</scope>                </dependency>                <dependency>                     <groupId>org.osgi</groupId>                      <artifactId>org.osgi.service.component.annotations</artifactId>                     <version>1.3.0</version>                 </dependency>                <dependency>                     <groupId>org.osgi</groupId>                     <artifactId>org.osgi.annotation</artifactId>                     <version>6.0.1</version>                     <scope>provided</scope>                </dependency>                <dependency>                     <groupId>org.osgi</groupId>                     <artifactId>org.osgi.service.metatype.annotations</artifactId>                     <version>1.3.0</version>                </dependency>                <dependency>                 <groupId>javax.annotation</groupId>                 <artifactId>javax.annotation-api</artifactId>                 <version>1.3.2</version>                 <scope>provided</scope>             </dependency>                                <!-- Logging Dependencies -->                <dependency>                 <groupId>org.slf4j</groupId>                 <artifactId>slf4j-api</artifactId>                 <version>1.7.21</version>                 <scope>provided</scope>             </dependency>                <!-- Apache Sling Dependencies -->                <dependency>                     <groupId>com.adobe.aem</groupId>                     <artifactId>uber-jar</artifactId>                     <version>6.5.0</version>                     <classifier>apis</classifier>                     <scope>provided</scope>                </dependency>                 <dependency>                     <groupId>org.apache.sling</groupId>                     <artifactId>org.apache.sling.models.api</artifactId>                     <version>1.3.6</version>                     <scope>provided</scope>                </dependency>                <dependency>                 <groupId>com.adobe.cq</groupId>                 <artifactId>core.wcm.components.all</artifactId>                 <type>zip</type>                 <version>${core.wcm.components.version}</version>             </dependency>             <dependency>                 <groupId>com.adobe.cq</groupId>                 <artifactId>core.wcm.components.examples</artifactId>                 <type>zip</type>                 <version>${core.wcm.components.version}</version>             </dependency>                  <!-- Servlet API -->                     <dependency>                 <groupId>javax.servlet</groupId>                 <artifactId>javax.servlet-api</artifactId>                 <version>3.1.0</version>                 <scope>provided</scope>             </dependency>                <dependency>                     <groupId>javax.servlet.jsp</groupId>                     <artifactId>jsp-api</artifactId>                     <version>2.1</version>                     <scope>provided</scope>                </dependency>                 <dependency>                 <groupId>javax.inject</groupId>                 <artifactId>javax.inject</artifactId>                 <version>1</version>             </dependency>                <!-- JCR -->                <dependency>                     <groupId>javax.jcr</groupId>                     <artifactId>jcr</artifactId>                     <version>2.0</version>                     <scope>provided</scope>                </dependency>                <!-- Taglibs -->                <dependency>                     <groupId>com.day.cq.wcm</groupId>                     <artifactId>cq-wcm-taglib</artifactId>                     <version>5.7.4</version>                     <scope>provided</scope>                </dependency>                <!-- Testing -->                <dependency>                     <groupId>junit</groupId>                     <artifactId>junit</artifactId>                     <version>4.12</version>                     <scope>test</scope>                </dependency>                <dependency>                     <groupId>org.slf4j</groupId>                     <artifactId>slf4j-simple</artifactId>                     <version>1.5.11</version>                     <scope>test</scope>                </dependency>                <dependency>                     <groupId>org.mockito</groupId>                     <artifactId>mockito-core</artifactId>                     <version>2.7.22</version>                     <scope>test</scope>                </dependency>                <dependency>                     <groupId>org.mockito</groupId>                     <artifactId>mockito-all</artifactId>                     <version>1.9.5</version>                     <scope>test</scope>                </dependency>                <dependency>                     <groupId>junit-addons</groupId>                     <artifactId>junit-addons</artifactId>                     <version>1.4</version>                     <scope>test</scope>                </dependency>           </dependencies>      </dependencyManagement>

dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>biz.aQute</groupId>
                <artifactId>bndlib</artifactId>
                <version>1.50.0</version>
                <scope>provided</scope>
            </dependency>

            <!-- Old OSGI Dependencies -->
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.compendium</artifactId>
                <version>4.2.0</version>
                <scope>provided</scope>
            </dependency>
           
           
           
            <!-- OSGi Dependencies -->
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.core</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.cmpn</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.service.component.annotations</artifactId>
                <version>1.3.0</version>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.annotation</artifactId>
                <version>6.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.service.metatype.annotations</artifactId>
                <version>1.3.0</version>
            </dependency>
            <dependency>
                <groupId>javax.annotation</groupId>
                <artifactId>javax.annotation-api</artifactId>
                <version>1.3.2</version>
                <scope>provided</scope>
            </dependency>
           
            <!-- Logging Dependencies -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.21</version>
                <scope>provided</scope>
            </dependency>
            <!-- Apache Sling Dependencies -->
            <dependency>
                <groupId>com.adobe.aem</groupId>
                <artifactId>uber-jar</artifactId>
                <version>6.5.0</version>
                <classifier>apis</classifier>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.models.api</artifactId>
                <version>1.3.6</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.adobe.cq</groupId>
                <artifactId>core.wcm.components.all</artifactId>
                <type>zip</type>
                <version>${core.wcm.components.version}</version>
            </dependency>
            <dependency>
                <groupId>com.adobe.cq</groupId>
                <artifactId>core.wcm.components.examples</artifactId>
                <type>zip</type>
                <version>${core.wcm.components.version}</version>
            </dependency>

            <!-- Servlet API -->
                <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.1.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
             <dependency>
                <groupId>javax.inject</groupId>
                <artifactId>javax.inject</artifactId>
                <version>1</version>
            </dependency>
            <!-- JCR -->
            <dependency>
                <groupId>javax.jcr</groupId>
                <artifactId>jcr</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Taglibs -->
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-taglib</artifactId>
                <version>5.7.4</version>
                <scope>provided</scope>
            </dependency>
            <!-- Testing -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.5.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.7.22</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.9.5</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit-addons</groupId>
                <artifactId>junit-addons</artifactId>
                <version>1.4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

grantc99475970

Avatar

grantc99475970

grantc99475970

06-08-2019

I compared your files with mine, and see no major differences. I updated a few plugin/dependency versions, but that didn't seem to help.

My issue is that the plugin activates, but the run function is never hit. Does yours run?

EDIT: Oh, I think it has to do with my cron-expression. I was using " * * * * * * " and never saw it run. Then I changed it to "0 * * * * ?" and then I saw it running. I guess I didn't understand how cron expressions work.

Answers (1)

Answers (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

958

Correct Answer

820

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

958

Correct Answer

820
Arun_Patidar
MVP

06-08-2019