yigit / android-priority-jobqueue

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
3.4k stars 395 forks source link

How to get correct jobs count from JobQueue if set same group id #429

Open shinjikao opened 6 years ago

shinjikao commented 6 years ago

I saw JobQueue's countReadyJobs(Constraint constraint) comment mentioned count as 1 since they cannot be run in parallel, but does exist other way to get job count by specific tag if I set same group id? e.g have 50 jobs set "A" group id in queue, and have 30 jobs set "B" group id in queue, How can I get 50 by countReadyJobs() method?

/**
     * Returns the # of jobs that are waiting to be run
     * @return The number of jobs that are waiting in the queue
     */
    int count();

/**
     * counts the # of jobs that can run now. if there are more jobs from the same group,
     * they are count as 1 since they cannot be run in parallel.
     * <p>
     * Exclude groups are guaranteed to be ordered in natural order.
     *
     * @param constraint The constraint to match the jobs
     *
     * @return The number of jobs that are ready to run
     */
    int countReadyJobs(@NonNull Constraint constraint);

My example code snippet

public SyncJob() {
        super(new Params(1).requireNetwork()
                // Make sure that providers can progress in parallel
                .groupBy(createTag())
                .addTags(createTag())
                .setPersistent(persistent)
                // To avoid duplicates
                .singleInstanceBy());
    }