Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process skipped clients #506

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Process skipped clients #506

wants to merge 30 commits into from

Conversation

junaidwarsivd
Copy link

import org.smartregister.giz.service.ReProcessSyncIntentService;
import org.smartregister.job.BaseJob;

public class GizReProcessJob extends BaseJob {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to GIZClientReprocessJob for now

if (fetchStatusSerializable instanceof FetchStatus) {
FetchStatus fetchStatus = (FetchStatus) fetchStatusSerializable;
if (fetchStatus.equals(FetchStatus.fetched)) {
GizReProcessJob.scheduleJobImmediately(GizReProcessJob.TAG);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we want to call the job once sync is complete eg sync is done fetching all the latest records and not successfully fetched one batch. I'm not sure if this is what is currently implemented



try {
if(formSubmissionIDs.size()>0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformat the code to fix spacing in the if statement

Comment on lines 42 to 45
e.printStackTrace();
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Timber to print exceptions. It sends exceptions to Crashlytics

try {
if(formSubmissionIDs.size()>0)
GizUtils.initiateEventProcessing(formSubmissionIDs);
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be generally catching Exception here

{
String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'";
String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'";
List<String> formSubmissionIDs = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list allows duplicates which might not be handled

@ekigamba
Copy link
Contributor

Fix codacy and build checks. Kindly make sure you fix this before requesting for a review


import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_FETCH_STATUS;

public class SyncStatusReciever extends BroadcastReceiver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to GizReprocessSyncStatusReceiver since this is only being used by the GizClientReprocessJob

SQLiteDatabase database = getReadableDatabase();
Cursor cursor = database.rawQuery(query, null);
int columnIndex = cursor.getColumnIndex("formSubmissionId");
if(cursor.getCount() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformat the code file to fix the spacing

@@ -21,4 +25,37 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType)
}
return hasEvent;
}

public void ReprocessClients()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 camelCase please and let's rename this to processSkippedClients or something a bit more descriptive enough that only unprocessed clients are being processed here


public class ReProcessSyncIntentService extends IntentService {

public static final String TAG = "ReValidateSyncIntentService";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have the tag similar to the name of the service


public class GIZClientReprocessJob extends BaseJob {

public static final String TAG = "GizReValidationJob";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this tag also to match the Job

…e action

added a check for existing formsubmission id while population the list
corrected the job tag
if(isComplete)
{
GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG);
Timber.d("fetch completed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log might be misleading

@@ -404,6 +404,8 @@ dependencies {

implementation "androidx.multidex:multidex:2.0.1"
testImplementation "androidx.work:work-testing:2.7.1"
androidTestImplementation 'androidx.test:runner:1.3.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are also applied for instrumentation tests that are not changed in this PR. Confirm that we need these and probably change this to testImplementation

if (cursor.getCount() > 0) {
cursor.moveToFirst();
do {
if (!ids.contains(cursor.getString(columnIndex)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time complexity for contains is n. I still believe that a HashSet is better here

@@ -21,4 +27,33 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType)
}
return hasEvent;
}

public void processSkippedClients() {
String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need to alias formSubmissionId here


public void processSkippedClients() {
String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'";
String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check previous comment on formSubmissionId

<service android:name="org.smartregister.sync.intent.SettingsSyncIntentService" />
<service android:name="org.smartregister.sync.intent.SyncIntentService" />
<service android:name=".service.ReProcessSyncIntentService"/>
<service android:name="org.smartregister.immunization.service.intent.VaccineIntentService" android:exported="true" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these services set as exported and why is this explicitly declared?

}
}

Timber.d("broadcast Recieved");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the log is too vague and it would be easier to understand if it was a bit more specific on the broadcast that was received

@ekigamba ekigamba changed the title added broadcast reciever and service to reprocess the client Process skipped client processing Mar 14, 2023
@ekigamba ekigamba changed the title Process skipped client processing Process skipped clients Mar 14, 2023
- Update immunization library to fix duplicate vaccines and services
- Fix client-core version
- Add config to close ec_client records when an OPD Close event is encountered
- Filter out closed records from the OPD register
- Update child register query to use ec_client.is_removed flag
- These events had not been previously processed due to a bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants