Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Created scheduler but not able to see log output in the project log

Avatar

Avatar
Boost 1
Level 1
ashwinikhaple
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 1
Level 1
ashwinikhaple
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Applaud 5
Affirm 1
View profile
ashwinikhaple
Level 1

15-04-2021

Below is the code for configuring the scheduler. You can refer to the screenshot of the configuration

 

@ObjectClassDefinition(
name = "AEM: SlingSchedulerConfiguration",
description = "Sling scheduler configuration"
)
public @interface SchedulerConfig
{

@AttributeDefinition(name = "Cron-job expression")
String scheduler_expression() default "*/10 * * * * ?";

@AttributeDefinition(name = "A parameter",
description = "Can be configured in /system/console/configMgr")
String myParameter() default "";
}

 

 

@Designate(ocd=SchedulerConfig.class)
@component(service=Runnable.class, immediate = true)
public class MyScheduler implements Runnable
{
private final Logger logger = LoggerFactory.getLogger(getClass());

private String myParameter;
@Override
public void run() {
logger.debug("MyScheduler is now running, myParameter='{}'", myParameter);
}

@activate
protected void activate(final SchedulerConfig config) {
myParameter = config.myParameter();
}
}

 

 

 

 

 

ashwinikhaple_1-1618470974589.png

 

 

View Entire Topic

Avatar

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

367 likes

Total Posts

462 posts

Correct Reply

134 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

367 likes

Total Posts

462 posts

Correct Reply

134 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile
asutosh_jena
Level 10

15-04-2021

Hi @ashwinikhaple 

 

Please update the below line of code:

 

@component(service=MyScheduler.class, immediate = true)

@Designate(ocd=SchedulerConfig.class)

public class MyScheduler implements Runnable

 

Service class should be your component class name.

 

Thanks!

 

ashwinikhaple
Hello @asutosh_jena, I modified service class to service name but still it is not working
asutosh_jena

HI @ashwinikhaple 

 

Please check the log level for your OSGi config.

As per code, it is set as DEBUG so in your logger configuration also it should be set as DEBUG.

if it's configured as INFO, DEBUG statements will not be logged into the log file.

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

 

Either change the log level in the OSGi config to DEBUG, else change the log level in code to logger.info if OSGI has already configured with INFO as the level.

 

Thanks!

ashwinikhaple

I am getting the below error

 

Caused by: org.apache.sling.api.scripting.ScriptEvaluationException:
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:416) [org.apache.sling.scripting.core:2.0.56]
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184) [org.apache.sling.scripting.core:2.0.56]
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:491) [org.apache.sling.scripting.core:2.0.56]
at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:621) [org.apache.sling.servlets.resolver:2.4.24]
... 68 common frames omitted
Caused by: org.apache.sling.api.SlingException:
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:691) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:533) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:342) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:97) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:603) [org.apache.sling.scripting.jsp:2.3.4]
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388) [org.apache.sling.scripting.core:2.0.56]
... 71 common frames omitted
Caused by: org.eclipse.jetty.io.RuntimeIOException: org.eclipse.jetty.io.EofException
at org.eclipse.jetty.server.ResponseWriter.isOpen(ResponseWriter.java:133) [org.apache.felix.http.jetty:4.0.8]
at org.eclipse.jetty.server.ResponseWriter.write(ResponseWriter.java:202) [org.apache.felix.http.jetty:4.0.8]
at java.io.PrintWriter.write(Unknown Source)

asutosh_jena

@ashwinikhaple I do not see any issue with the code. This error is for some other code.

Can you please put the complete error message to know where this error is coming exactly?

 

Also for the Scheduler, please use the below CRON expression. This will ensure the scheduler is running every 1 min and it will print the log. 

0 0/1 * 1/1 * ? *

 

Else you can add a logger statement in the @activate method which will print he log when you deploy the code.

 

Do let me know if this does not work.

 

@Activate // This will execute each time the bundle get's deployed into the system i.e. each deployment
protected void activate(final SchedulerConfig schedulerConfig) {
log.info("***** :: Activate :: *****");
myParameter = schedulerConfig.myParameter();
}
@Override
public void run() { // This will execute each time the scheduler runs.
log.info("***** :: run :: Start :: *****");
log.info("***** :: My Scheduler is Running :: {}", myParameter);
log.info("***** :: run :: End :: *****");
}

Thanks!