[opencms-dev] Documentation/examples of Scheduled Tasks?

Thorsten Inboden opencms at inboden.de
Wed Nov 13 19:21:30 CET 2002


Hi Michael,

to run scheduled tasks, you first have to write a class implementing the
interface I_CmsCronJob:

public class YourClass implements I_CmsCronJob {
    public String launch(CmsObject cms, String parameter) throws Exception {

     <put in your code here>

    return null;
     }
}

then you have to add your task (administration view / scheduled tasks), i.
e. :

00 07 * * * admin Administrators YourClass



(YourClass will be invoked at 7 a.m. every day)



that's it.





Here is a small example to run a static export for backup function once a
day, generating the files backup_1.zip to backup_7.zip every week.


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.opencms.core.I_CmsCronJob;
import com.opencms.file.CmsObject;

public class backup_ajax implements I_CmsCronJob {

    public String launch(CmsObject cms, String parameter) throws Exception {

    cms.writeExportPath("<yourBackupFolderPath>");

    // set all paths for static export
    String[] pathArray = new String[] {
        "/content/",
        "/pics/",
        "/mystuff/"
        };

    // get date for filename extension
    Calendar today = Calendar.getInstance();
    today.setTime(new Date());
    int day_of_week = (today.get(Calendar.DAY_OF_WEEK));

    String fileName = "myBackup_" + day_of_week;

    boolean includeSystem = false; // include system folder?
    boolean incremental = false; // full or incremental backup

    // start export of choosen recources
    cms.exportResources(fileName,pathArray,includeSystem,!incremental);

    return null;
    }
}

Best Regards,
Thorsten

----- Original Message -----
From: "Michael Matti" <Michael.Matti at sas.com>
To: <opencms-dev at opencms.com>
Sent: Monday, November 11, 2002 10:48 PM
Subject: [opencms-dev] Documentation/examples of Scheduled Tasks?


>
> I've been browsing the list archives for tips on scheduled tasks ...
several folks have asked about it, but no one's offered answers. Well, let
me try once again: can anyone explain how to use the scheduled tasks
feature, and maybe provide an example?
>
> Haven't found anything on the subject in the documentation, and all the
dialog box shows is a terse statement of syntax. What I'm looking for,
specifically, is a way to trigger the static export of a project in the
middle of the night.
>
> Anyone succeeded with this? Thanks much for any advice.
>
>
> M. C. Matti
> mimatt at sas.com




More information about the opencms-dev mailing list