0

我在尝试开发最简单的 jBilling 预定插件时遇到了一个奇怪的问题。我想制作一个每分钟执行一次的插件,但会运行更长的时间。我需要这个来了解 jBilling 将如何以这种方式运行 - 只运行一个插件实例或每分钟启动一个新实例。所以我编写了插件(见下文)并使用 cron_exp = "* * * * " 安装它(我还尝试了 " 0-23 * * *" 和其他变体)。但是现在,当 jBilling 启动时,我在日志中出现以下错误:

2013-10-28 16:28:26,215 调试 [com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskManager] 应用任务 com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin 2013-10-28 16:28:26,217 调试[com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskManager] 创建 com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin 的新实例 2013-10-28 16:28:26,225 WARN [com.sapienter.jbilling.server .util.Bootstrap] 无法安排可插入任务 [com.sapienter.jbilling.server.MyPlugins.testLongTimeRunningPlugin] 2013-10-28 16:28:26,225 调试 [com.sapienter.jbilling.server.util.Bootstrap] 启动作业调度器

所以我想知道为什么它不能被安排,我该如何解决它?这是代码:

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!");
        }
    }
}

`

4

3 回答 3

0

Jbilling 可插入任务由 JBilling 系统本身处理,您不需要提供调度程序行为。您唯一需要做的就是在配置菜单中编写任务(自定义类)配置并将条目插入表中。

当您要创建Task时,您需要扩展/实现PlugableTask并需要在plugabletaskparameter表中指定类名,并具有适当的类别类型,例如:如果您要创建支付任务,则类别类型为6

于 2013-11-26T19:33:57.400 回答
0

在使用 5 参数 cron 表达式时,我们还遇到了“无法安排可插入任务”错误。更改为 6 参数表达式对我们有用,并允许安排任务。

例如,要安排每一分钟,我们将使用“0 * * * * ?” 而不是“0 * * * *”。

于 2014-09-08T08:16:02.053 回答
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;
    }
}
于 2014-12-02T14:17:50.540 回答