• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-client-core / #181

06 Aug 2024 05:51AM UTC coverage: 68.398% (+0.003%) from 68.395%
#181

Pull #925

github

web-flow
Merge 605302deb into 4fcf06cf5
Pull Request #925: migrate SyncserviceJob to work manager

18313 of 26774 relevant lines covered (68.4%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.17
opensrp-core/src/main/java/org/smartregister/job/BaseJob.java
1
package org.smartregister.job;
2

3
import android.content.Context;
4
import android.content.Intent;
5

6
import com.evernote.android.job.Job;
7
import com.evernote.android.job.JobManager;
8
import com.evernote.android.job.JobRequest;
9
import com.evernote.android.job.util.support.PersistableBundleCompat;
10

11
import org.smartregister.AllConstants;
12

13
import java.util.concurrent.TimeUnit;
14

15
import timber.log.Timber;
16

17
/**
18
 * Created by ndegwamartin on 05/09/2018.
19
 */
20
public abstract class BaseJob extends Job {
1✔
21

22

23
    public static void scheduleJob(String jobTag, Long start, Long flex) {
24

25
        if (JobManager.instance().getAllJobRequestsForTag(jobTag).isEmpty()) {
1✔
26

27
            boolean toReschedule = start < TimeUnit.MINUTES.toMillis(15); //evernote doesn't allow less than 15 mins periodic schedule, keep flag ref for workaround
1✔
28

29
            PersistableBundleCompat extras = new PersistableBundleCompat();
1✔
30
            extras.putBoolean(AllConstants.INTENT_KEY.TO_RESCHEDULE, toReschedule);
1✔
31

32
            JobRequest.Builder jobRequest = new JobRequest.Builder(jobTag).setExtras(extras);
1✔
33

34
            jobRequest.setPeriodic(TimeUnit.MINUTES.toMillis(start), TimeUnit.MINUTES.toMillis(flex));
1✔
35

36
            try {
37

38
                int jobId = jobRequest.build().schedule();
1✔
39
                Timber.d("Scheduling job with name " + jobTag + " : JOB ID " + jobId + " periodically every " + start + " minutes and flex value of " + flex + " minutes");
1✔
40

41
            } catch (Exception e) {
×
42
                Timber.e(e);
×
43
            }
1✔
44
        } else {
1✔
45
            Timber.d("Skipping schedule for job with name " + jobTag + " : Already Exists!");
×
46

47
        }
48
    }
1✔
49

50
    /**
51
     * For jobs that need to be started immediately
52
     */
53
    public static void scheduleJobImmediately(String jobTag) {
54

55
        int jobId = new JobRequest.Builder(jobTag)
×
56
                .startNow()
×
57
                .build()
×
58
                .schedule();
×
59

60
        Timber.d("Scheduling job with name " + jobTag + " immediately with JOB ID " + jobId);
×
61

62
    }
×
63

64
    @Override
65
    protected void onReschedule(int newJobId) {
66

67
        Timber.d("Rescheduling job with name " + this.getParams().getTag() + " JOB ID " + newJobId);
×
68
    }
×
69

70
    //Custom app context method to aid unit testing
71
    public Context getApplicationContext() {
72
        return super.getContext();
1✔
73
    }
74

75
    protected void startIntentService(Intent intent) {
76
        try {
77
            getApplicationContext().startService(intent);
1✔
78
        } catch (Exception e) {
×
79
            Timber.e(e);
×
80
        }
1✔
81
    }
1✔
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc