android-priority-jobqueue icon indicating copy to clipboard operation
android-priority-jobqueue copied to clipboard

when the job set requireNetwork and persist ,onRun will execute twice

Open shingohu opened this issue 8 years ago • 6 comments

1.open the network 2.post the job (the job will onRun but not done) 3.close the network (when execute uploadImage method will exception) 4.open the network 5.the onRun method will execute twice

version 2.0.1

the simple code ` public class FeedbackTestJob extends Job {

public FeedbackTestJob(String con, String contact, List<String> images) {
    super(new Params(Priority.LOW).requireNetwork().persist());
    LogUtils.d("onCreate" + getId());
}

@Override
public void onAdded() {
    LogUtils.d("onAdded" + getId());
}


@Override
public void onRun() throws Throwable {

    LogUtils.d("onRun" + getId());

    Thread.sleep(5000);

    uploadImage();

    LogUtils.d("end");


}

/**
 */
private void uploadImage() {
    //uploadImage code
}


@Override
protected void onCancel(int cancelReason, @Nullable Throwable throwable) {

}


@Override
protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
    LogUtils.d("error");

    if (runCount == 4)
        return RetryConstraint.CANCEL;

    return RetryConstraint.RETRY;
}

}`

shingohu avatar Jun 22 '17 06:06 shingohu

` public void initJobManager(Context context) { Configuration.Builder builder = new Configuration.Builder(context) .customLogger(new CustomLogger() { private static final String TAG = "shenluntikuapp job";

                @Override
                public boolean isDebugEnabled() {
                    return true;
                }

                @Override
                public void d(String text, Object... args) {
                    Log.d(TAG, String.format(text, args));
                }

                @Override
                public void e(Throwable t, String text, Object... args) {
                    Log.e(TAG, String.format(text, args), t);
                }

                @Override
                public void e(String text, Object... args) {
                    Log.e(TAG, String.format(text, args));
                }

                @Override
                public void v(String text, Object... args) {

                }
            })
            .minConsumerCount(1)
            .maxConsumerCount(3)
            .loadFactor(3)//
            .consumerKeepAlive(120);
    jobManager = new JobManager(builder.build());
}`

shingohu avatar Jun 22 '17 06:06 shingohu

@shingohu did you find a solution?

artemasoyan avatar Sep 05 '17 14:09 artemasoyan

@wandering7man do you have this problem too?
version 1.3.5 is not problem

shingohu avatar Sep 08 '17 10:09 shingohu

@shingohu I can't reproduce it by myself, but our users sometimes can, very flaky bug.

artemasoyan avatar Sep 08 '17 10:09 artemasoyan

@wandering7man 1.open the network 2.post the job (the job will onRun but not done) 3.close the network (when execute uploadImage method will exception) 4.open the network 5.the onRun method will execute twice like this can't reproduce?

shingohu avatar Sep 08 '17 10:09 shingohu

@shingohu nope :(

artemasoyan avatar Sep 08 '17 10:09 artemasoyan