Question

I have a strange problem while trying to develope simplest jBilling scheduled plugin. I want to make a plugin which will be executed every minute, but will run for a longer time. I eed this to understand how jBilling will act in this way - run just a single instance of plugin or start new instance every minute. So I wrote the plugin (see below) and installed it with cron_exp = "* * * * " (I also tried " 0-23 * * *" and other variants). But now, when jBilling starts I have following error in logs:

2013-10-28 16:28:26,215 DEBUG [com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskManager] Applying task com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin 2013-10-28 16:28:26,217 DEBUG [com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskManager] Creating a new instance of com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin 2013-10-28 16:28:26,225 WARN [com.sapienter.jbilling.server.util.Bootstrap] Failed to schedule pluggable task [com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin] 2013-10-28 16:28:26,225 DEBUG [com.sapienter.jbilling.server.util.Bootstrap] Starting the job scheduler

So I wonder why it can't be scheduled and how can I fix it? Here is the code:

public class testLongTimeRunningPlugin extends AbstractCronTask {
    public static final String taskName = testLongTimeRunningPlugin.class.getCanonicalName();
    private static final Logger LOG = Logger.getLogger(draftAPIgetProductCategories.class);
    private static final int time = 5;

    @Override
public String getTaskName() {
        return taskName;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        LOG.debug("Starting and waiting for " + time + " minutes");

        try{
            TimeUnit.MINUTES.sleep(time);
            LOG.debug("Completed");
        }catch (InterruptedException e){
            LOG.debug("Interrupted!");
        }
    }
}

`

Was it helpful?

Solution

Jbilling plugable tasks are meant handle by the JBilling system itself, and you dont need to provide scheduler behavior. Only thing you would need to do is, write task (custom class) configure in Configuration menu and insert the entry in the table.

When you want to create Task, you would need to extend/implement the PlugableTask and need to specify the class name in the plugabletaskparameter table, with proper category type, for eg: if you want to create payment task , category type is 6

OTHER TIPS

We also encountered the "Failed to schedule pluggable task" error when using a 5-argument cron expression. Changing to the 6-argument expression worked for us and allowed the task to be scheduled.

For example, to schedule every minute we would use "0 * * * * ?" rather than "0 * * * *".

try this

package com.sapienter.jbilling.server.pluggableTask;

import com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskException;
import com.sapienter.jbilling.server.process.task.AbstractBackwardSimpleScheduledTask;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SimpleTrigger;

import java.util.Calendar;
import java.util.concurrent.atomic.AtomicBoolean;

public class TutorialSimpleScheduledTask extends AbstractBackwardSimpleScheduledTask {
    private static final Logger LOG = Logger.getLogger(TutorialSimpleScheduledTask.class);
    private static final AtomicBoolean running = new AtomicBoolean(false);

    public String getTaskName() {
        return "Tutorial Simple Scheduled Task: " + getScheduleString();
    }

    public void execute(JobExecutionContext context) throws JobExecutionException {
        super.execute(context);//_init(context);

        if (running.compareAndSet(false, true)) {
            LOG.debug("SimpleScheduledTask is running - " + Calendar.getInstance().getTime());
            running.set(false);
        } else {
            LOG.warn("Failed to trigger tutorial simple process at " + context.getFireTime()
                    + ", another process is already running.");
        }
    }

    /**
     * Returns the scheduled trigger for the mediation process. If the plug-in is missing
     * the {@link com.sapienter.jbilling.server.process.task.AbstractSimpleScheduledTask}
     * parameters use the the default jbilling.properties process schedule instead.
     *
     * @return mediation trigger for scheduling
     * @throws com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskException
     *          thrown if properties or plug-in parameters could not be parsed
     */
    @Override
    public SimpleTrigger getTrigger() throws PluggableTaskException {
        SimpleTrigger trigger = super.getTrigger();

        // trigger start time and frequency using jbilling.properties unless plug-in
        // parameters have been explicitly set to define the mediation schedule
        if (useProperties()) {
            LOG.debug("Scheduling tutorial process from jbilling.properties ...");
            trigger = setTriggerFromProperties(trigger);
        } else {
            LOG.debug("Scheduling tutorial process using plug-in parameters ...");
        }

        return trigger;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top