Jahia Dev Forum > Create cron job...

0 (0 Good)
0 (0 Bad)

Create cron job / background job in jahia (custom defined)

by  Create cron job / background job in jahia (custom defined) »  2015/07/07 16:37

I want to create a cron job in jahia which should run every 10 mins and then gets the latest updates from the news list and blogs. It should then create an RSS with it and then send it to  the people who have subscribed

Any suggestions and comments would be very helpful to me

Thanks

Create cron job / background job in jahia (custom defined)
Number of messages  1
Not registered
0 (0 Good)
0 (0 Bad)

Re: Create cron job / background job in jahia (custom defined)

by  wassek »  2015/07/13 15:16

Hello,

 

In jahia 6.6.X.X and higher, Quartz is integrated, and you could implement own cron jobs very simple. You have to implement a job class which should inherit from org.jahia.services.scheduler.BackgroundJob and you have to implement the method:

 public void executeJahiaJob(JobExecutionContext ctx) throws Exception {

 

}

in the JobExecutionContext  you get all information about parameters, user all other job specific things.

So it means in this method you have to implement your job. In your case create the rss inside.

 

After that install this class file on your application server. You can put it in a module when you have the correct dependencies or you could put it as a main class directly in WEB-INF/classes or in a jar file in WEB-INF/lib in your jahia webapp.

After that you can register the job for instance in the groovy console in the jahia tools (http://yourserver:yourport/toos) like, when you execute follow code (org.jahia.background.YourOwnJOBImplementation is in that case the implemented job class):

   org.quartz.JobDetail detail = org.jahia.services.scheduler.BackgroundJob.createJahiaJob("Job Name", org.jahia.background.YourOwnJOBImplementation.class);

    // you could set some parameters for the job if it is needed in the dataMap. This parameters would be available in the YourOwnJOBImplementation class

      org.quartz.JobDataMap dataMap = detail.getJobDataMap();
        dataMap.put("parameter1", "ACMESPACE");
      org.quartz.CronTrigger trigger = new org.quartz.CronTrigger("jobName", "Maintanace", "0 0/10 * * * ?");
      org.jahia.registries.ServicesRegistry.getInstance().getSchedulerService().getScheduler().scheduleJob(detail, trigger);

 

That means the executeJahiaJob method will be called every 10 minutes. And will be processed on the ProcessingNode (if you have a cluster). To remove the job from the scheduler you could use the jobadministration in the jahia tools: http://server:port/tools/jobadmin.jsp 

Another way would be to configure a spring file with a ramJob (means this job is not stored in DB, and will be started automatically when the server starts. For that you have to define a spring configuration file with a bean like:

    <bean parent="jobSchedulingBean">
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="name" value="ContentHistoryPurgeJob" />
                <property name="jobClass" value="org.jahia.services.scheduler.JSR223ScriptJob" />
                <property name="group" value="Maintenance" />
                <property name="description" value="Content history purge" />
                <property name="jobDataAsMap">
                    <map>
                        <entry key="userkey" value=" system " />
                        <entry key="jobScriptPath" value="/WEB-INF/var/scripts/groovy/purgeContentHistory.groovy" />
                    </map>
                </property>
            </bean>
        </property>
        <property name="trigger">
            <bean class="org.quartz.CronTrigger">
                <property name="name" value="ContentHistoryPurgeTrigger"/>
                <!-- run every year -->
                <property name="cronExpression" value="0 0 0 L DEC ? *"/>
                <!-- run every hour to debug -->
                <!--property name="cronExpression" value="0 0 * * * ?"/-->
            </bean>
        </property>
    </bean>

 

This example is a jahia default job to purge the content History. In that case you can implement instead the class a groovy script which can create the rss.

NOTE: a ram job will be executed on every node in a cluster where it is configured.

I hope it helps,

regards,

Werner

Werner Assek (wassek)

Number of messages  26
Registration date
0 (0 Good)
0 (0 Bad)

Re: Create cron job / background job in jahia (custom defined)

by  dgriffon »  2015/07/15 05:51

Hello,

To gather the news to be sent, you can store the date of the last query then execute a query to get all modified news/blog within a site since this date

have a look to our newletter module :

https://github.com/Jahia/JahiApp-Newsletter

this module shows you how to send a mail with a jahia content. This should help you to build the rss feed within the mail.

you can  have a look also to our rss module to get information on how to build the rss feed

https://github.com/Jahia/rss

David

David Griffon (dgriffon)

Number of messages  76
Registration date
0 (0 Good)
0 (0 Bad)

Re: Re: Create cron job / background job in jahia (custom defined)

by  Thanks »  2015/07/24 15:21

May thanks to you all, however I was able to get the the way to create a cron job and its almost the same way that you have told. Thanks for your informations and support

Thanks
Number of messages  1
Not registered
0 (0 Good)
0 (0 Bad)

Re: Re: Create cron job / background job in jahia (custom defined)

by  Thank you  »  2015/07/24 15:23

Thank you very much for the inforamtion "dgriffon"

Thank you
Number of messages  1
Not registered
0 (0 Good)
0 (0 Bad)

Moderate/control Forum

by  Jahia Forum »  2015/07/24 15:36

Hi there,

I am using the default Jahia Forum component for our applcation.With this component, we can create ROOMs. I want something like I need only certain application user to give previllage to create rooms. As a root user I am able to make all/complete changes.

In the "segment-roles" (a groupname), I will configure certain users to have the previllage of creating the rooms/and section. Aslo I need to moderate the room and section that are being created.

In the current default Forum, we have the button "Moderate Room", but that does not work. I am new to Jahia and it will be great if we can modify the existing Jahia forum code.

I got the code base for Jahia forum from "https://github.com/Jahia/JahiApp-Forum"

Jahia Forum
Number of messages  1
Not registered
0 (0 Good)
0 (0 Bad)

by  tElenaavem »  2017/08/18 10:39

> www.oplata-vklike.tk < Вывод заработанных средств ежедневно в течении нескольких минут.
tElenaavem
Number of messages  1
Not registered
Contact
Share
Feedback

Get in touch

Whether you are a current user or if you are just evaluating Jahia, we are here to help.

Contact us

Share this page