How to create scheduler to run the sling servlet? | Community
Skip to main content
Level 2
May 24, 2022

How to create scheduler to run the sling servlet?

  • May 24, 2022
  • 3 replies
  • 2215 views

Hi All,

 

We have a requirement to execute the sling servlet on the monthly basis. Actually I have added the content path of the sites in xml and updated this in content/dam, here I have used query builder for this and I wanted to execute this particular servlet on the monthly basis to generate the xml.

 

Please let me know if anyone has worked on the similar issue.

 

Thanks,

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

3 replies

Adobe Employee
May 24, 2022
arunpatidar
Community Advisor
Community Advisor
May 24, 2022

I think, you should move the servlet logic into the osgi service/component e.g. DoSomethingService and call that service in servlet e.g. ThisMyServlet and in your scheduler MyScheduler.

 

If you do not need servlet you can simply remove the servlet e.g. ThisMyServlet

Arun Patidar
Level 2
May 24, 2022

Hi @arunpatidar ,

I have done the same way. I have created a service and called this service in servlet. Do I need to call this service in scheduler as well?

 

Thanks,

milind_bachani
Adobe Employee
Adobe Employee
May 24, 2022

Hi @aaqibk92586681 ,

 

Whatever @arunpatidar suggested should help.

However, the use case you mentioned only needs a service (DoSomethingService) & a scheduler(MyScheduler that invokes DoSomething.doing()) which uses the service at given frequency according to CRON expression.

But, incase you also need an manual option to do the task, you can have a servlet at some path (/bin/execute/dosomething) and call it if required.

This approach will enable :
1. Scheduled job to do the task using scheduler at given frequency.
2. Option to also do the same job on demand by hitting the servlet endpoint.

And both would be using the same service custom code (here, DoSomething.doing())


Thanks,

Milind

Level 2
May 25, 2022

Hi @milind_bachani ,

For now we are hitting below servlet manually to add the xml file in dam.

http://localhost:4502/bin/microsites/xmlgenarate?sitename=/content/we-retail/us/en/products

I created a service class to generated the searched path via query builder and I have called this particular service in servlet and I wanted to this servlet run on monthly basis that's why I wanted to add scheduler. Is there any way we can configure servlet path in scheduler config to execute this servlet and after running the scheduler the above process will generate automatically.

 

Thanks,

  

Adobe Employee
October 14, 2024

Hi @aaqibk92586681 

How did you handle the situation?