[opencms-dev] Scheduled Jobs

Brabenetz, Harald harald.brabenetz at bearingpointconsulting.com
Wed Aug 11 09:46:08 CEST 2010


Hi,
we create a deaktivated example-Job at startup (ModuleAction):

    public void initialize(//
            final CmsObject adminCms, //
            final CmsConfigurationManager configurationManager, //
            final CmsModule module) {

        if (!isScheduledJobRegistered(MyScheduledJob.class)) {
            try {
                scheduleMyJob(adminCms);
            } catch (final CmsRoleViolationException e) {
                throw new IllegalStateException(//
                    "Shouldn't happen, the Admin User has enough role permissions.", e);
            } catch (final CmsSchedulerException e) {
                throw new IllegalStateException(//
                    "Shouldn't happen, the default-Configuration should always be valid.", e);
            }
        }

        // show Debug-Logging-Informations
        super.initialize(adminCms, configurationManager, module);
    }

    /**
     * Check if there is a Scheduled Job with the given Class.
     *
     * @param jobClass The ScheduledJob Class implementation.
     * @return true if a Scheduled Job where found
     */
    private boolean isScheduledJobRegistered(Class<? extends I_CmsScheduledJob> jobClass) {
        final String className = jobClass.getName();

        final List<CmsScheduledJobInfo> jobs = getAllScheduleJobs();
        for (final CmsScheduledJobInfo cmsScheduledJobInfo : jobs) {
            if (className.equals(cmsScheduledJobInfo.getClassName())) {
                return true;
            }
        }
        return false;
    }

    private void scheduleMyJob(final CmsObject adminCms)
            throws CmsRoleViolationException, CmsSchedulerException {
        final CmsScheduledJobInfo schduleJobInfo = new CmsScheduledJobInfo();

        // Job Settings
        schduleJobInfo.setJobName("My Scheduled Job");
        schduleJobInfo.setClassName(MyScheduledJob.class.getName());
        // every five Minutes
        schduleJobInfo.setCronExpression("0 0/5 * * * ?");
        schduleJobInfo.setReuseInstance(true);
        schduleJobInfo.setActive(false);

        // Context info
        final CmsContextInfo contextInfo = new CmsContextInfo();
        contextInfo.setUserName("Admin");
        contextInfo.setProjectName("Offline");
        schduleJobInfo.setContextInfo(contextInfo);

        // Parameters
        final SortedMap<String, String> parameters = new TreeMap<String, String>();
        parameters.put("MyConfigurationParameter", "file://D:/OPENCMS-MyJobWorkFolder");
        schduleJobInfo.setParameters(parameters);

        OpenCms.getScheduleManager().scheduleJob(adminCms, schduleJobInfo);
    }

The OpenCms-Administrator must only customize the example configration (Job-Parameters) and activate the Job.

With friendly regards,
Harald

-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Michael Emmerich
Sent: Mittwoch, 11. August 2010 09:24
To: The OpenCms mailing list
Subject: Re: [opencms-dev] Scheduled Jobs

Hi,

if you have your own scheduled job, you can use it by entering the class
name.

Sorry, so far its not possible to automatically extend the select box
there, but this would be indeed a nice enhancement.

Maybe someone could add an enhancement proposal in bugilla for it :)

Michael

Am 11.08.2010 09:19, schrieb Paul-Inge Flakstad:
> Hi Daniel and Mario,
>
> Would be cool if a future update/release could make these
> configurable instead.
>
> Best regards,
> Paul
>
>> -----Original Message-----
>> From: opencms-dev-bounces at opencms.org
>> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Mario Jäger
>> Sent: 11. august 2010 09:13
>> To: The OpenCms mailing list
>> Subject: Re: [opencms-dev] Scheduled Jobs
>>
>> Hi Daniel,
>>
>> The jobs in the select box are hard coded in the method
>> org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoD
>> ialog.getComboClasses().
>>
>> --
>> Kind Regards,
>> Mario.
>>
>> -------------------
>> Mario Jäger
>>
>> Alkacon Software GmbH  - The OpenCms Experts
>> http://www.alkacon.com - http://www.opencms.org
>>
>>
>> Daniel Cassiani Rezende schrieb:
>>> Howdy, folks,
>>>
>>>
>>> Please, how can I make a Java class I created show up at
>> the Select in
>>>
>>> Administration View>   Scheduled Jobs Management>   New Job
>>> Job settings>  Java Class ???
>>>
>>>
>>> I compiled it in my<module>/classes folder, created it
>> with implementing I_CmsScheduledJob, and nothing... nor can I
>> find a XML to put it or so...
>>>
>>>
>>> Thanks in advance,
>>>
>>> Daniel
>>>
>>>
>>>
>> --------------------------------------------------------------
>> ----------
>>>
>>> Esta mensagem e seus anexos podem conter informações
>> confidenciais ou privilegiadas. Se você não é o destinatário
>> dos mesmos você não está autorizado a utilizar o material
>> para qualquer fim. Solicitamos que você apague a mensagem e
>> avise imediatamente ao remetente. O conteúdo desta mensagem e
>> seus anexos não representam necessariamente a opinião e a
>> intenção da empresa, não implicando em qualquer obrigaçâo ou
>> responsabilidade da parte da mesma.
>>> This message may contain confidential and/or privileged
>> information. If you are not the addressee or authorized to
>> receive this for the addressee, you must not use, copy,
>> disclose or take any action based on this message or any
>> information herein. If you have received this message in
>> error, please advise the sender immediately by reply e-mail
>> and delete this message. The contents of this message and its
>> attachments do not necessarily express the opinion or the
>> intention of the company, and do not implies any legal
>> obligation or responsibilities from this company.
>>>
>>>
>> --------------------------------------------------------------
>> ----------
>>>
>>>
>>> _______________________________________________
>>> This mail is sent to you from the opencms-dev mailing list
>>> To change your list options, or to unsubscribe from the
>> list, please visit
>>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list,
>> please visit
>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev

--
Kind Regards,
Michael.

-------------------
Michael Emmerich

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org


_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev

INFONOVA GmbH
Sitz: Unterpremstätten bei Graz
Firmenbuchgericht: Landesgericht für ZRS Graz
Firmenbuchnummer: FN 44354b



More information about the opencms-dev mailing list