【问题标题】:How to cancel a recurring job in firebase job dispatcher如何取消firebase作业调度程序中的重复作业
【发布时间】:2017-02-17 20:00:21
【问题描述】:

我创建了一个循环作业,我想在满足某些条件时取消循环作业。

final Job.Builder builder = dispatcher.newJobBuilder()
                .setTag("myJob")
                .setService(myJobService.class)
                .setRecurring(true)
                .setTrigger(Trigger.executionWindow(30, 60));

如何在 firebase 中取消作业?

【问题讨论】:

    标签: firebase-job-dispatcher


    【解决方案1】:

    GitHub 上的自述文件说:

    Driver是一个接口,代表一个可以调度的组件, 取消并执行作业。唯一捆绑的驱动程序是 GooglePlayDriver,它依赖于 Google 内置的调度程序 播放服务。

    所以取消是您正在使用的驱动程序的一部分。检查the code of the driver interface有两种方法可以取消作业:

    /**
     * Cancels the job with the provided tag and class.
     *
     * @return one of the CANCEL_RESULT_ constants.
     */
     @CancelResult
     int cancel(@NonNull String tag);
    
    /**
     * Cancels all jobs registered with this Driver.
     *
     * @return one of the CANCEL_RESULT_ constants.
     */
     @CancelResult
     int cancelAll();
    

    所以在你的情况下你必须打电话:

    dispatcher.cancel("myJob");
    

    dispatcher.cancelAll();
    

    调度器会为你调用驱动对应的方法。如果你愿意,你也可以直接在你的驱动程序上调用方法myDriver.cancelAll()like it is done in the sample app which comes with the GitHub project.

    所选方法将返回以下常量之一:

    public static final int CANCEL_RESULT_SUCCESS = 0;
    public static final int CANCEL_RESULT_UNKNOWN_ERROR = 1;
    public static final int CANCEL_RESULT_NO_DRIVER_AVAILABLE = 2;
    

    【讨论】:

    • 有没有提到这个的文件?
    • 不是真的,我在源代码中找到的。我把答案充实了一点,看看吧。
    猜你喜欢
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多