Tuesday, October 2, 2012

How to implement CQ scheduler to run on a event

Use Case:

1) You want to implement a scheduler to run on a specific event. That event could be any thing ranging from any Node action (Add,Modify,Delete) or any replication action (Activate, Deactivate, Reverse)

Pre requisite:

1) http://sling.apache.org/site/eventing-and-jobs.html
2) http://felix.apache.org/site/apache-felix-event-admin.html
3) http://www.osgi.org/javadoc/r4v41/org/osgi/service/event/package-summary.html
4) http://sling.apache.org/apidocs/sling5/org/apache/sling/event/package-summary.html

Implementation:

Step 1




Step 2: Handler to perform action




Note: you can find some more code example at http://wemcode.wemblog.com

8 comments:

  1. It worked! Thanks for the code, I would not be able to do this on my own. I am amazed on how you did this hard coded. I always wanted to be a programmer and I had spent time on reviewing but I guess its either you have it or you don't.

    ReplyDelete
  2. Clear codes and looks professional. Hopefully this is easy to implement.

    ReplyDelete
  3. this is not look like scheduler but i found good implementation of event handler

    ReplyDelete
    Replies
    1. Scheduler is getting generated at run time here using this.scheduler.fireJobAt(path, eventJob, props, endDate);

      You can find better example of normal scheduler (Independent of event) from here http://wemcode.wemblog.com/invlidate_cache

      Yogesh

      Delete
  4. Hi Yogesh,

    Is there any console/way to check the scheduled jobs queue in CQ 5.5? We are removing the scheduled jobs using scheduler.removeJob("JobName") , but we want to make sure the jobs are indeed getting removed.

    Thanks

    ReplyDelete
    Replies
    1. Kundan,
      You can see all scheduled Job under HOST:PORT/system/console/status-slingscheduler
      Yogesh

      Delete
    2. Hi Yogesh,

      I have a Sling servlet code that is returning me some mbean information.
      However, I would want to schedule it using sling scheduler.
      Can you please let me know, as to how this could be done.
      I am struggling to get this to work.

      Any thoughts/pointers/code would be really helpful.

      Delete
  5. Custom Term Paper Service industry has grown steadily in provision of Legitimate Term Paper Services and high quality Custom Term Paper Writing Services which is preferred by scholars worldwide.

    ReplyDelete