-
Notifications
You must be signed in to change notification settings - Fork 10
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
XDS sender should persist last successful request date #98
base: main
Are you sure you want to change the base?
Conversation
|
||
@Entity | ||
@Table(name = "request_date") | ||
public class RequestDate extends BaseOpenmrsObject{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments here:
- If we're going to create a whole table for this, it should be associated to the specific task, so that we can use this same structure for multiple things. However, I think this should be backed by a GP or something similar.
- OpenMRS best practice is for tables to always use the module id of the module defining them, so
xds_sender_request_date
rather thanrequest_date
. This way, the module will not interfere with other modules (that follow this rule) and also, it makes it clearer what the table is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i ddint want to inntially use a table.
Thought about just storing the timeStamp in a text file some where, though it also came with just a few other considerations
About usig a GP , do you mean a GP for allowing allowing these objects to be persisted ??
like
if (GP.xds_persist_request_timestamp){
// persist the request date
}
About associating this to the specific task
I also though about Associating this to some kind of Object but i failed to get a resonable one
What Task exactly did you mean ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PullNotificationsTask
instance associated with the run. The idea is to have a pattern we can use for multiple similar tasks (for future cases where we may not be just exchanging labs, but possibly other data from the HIE).
In terms of GP, basically what we're storing is a single datetime, which can be represented as a string, so why not just store that string as, e.g., xds.sender.<PullNotificationsTaskUuid>.lastSuccessfulRun
? It's still functionally backed by the DB, but it doesn't require creating the table, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats true , i though about doing that at some point , and thought i would misusing the GP.
But let me just simply use a GP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so when you say xds.sender.<PullNotificationsTaskUuid>.lastSuccessfulRun
,
do you mean creating a new GP on every succesful run ??
I though i only need to use a single GP xds.sender.PullNotificationTask.lastSuccessfulRun
and just keep updating the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine too, but, no I was thinking of the UUID for the specific task (each scheduled task is stored in the database as an object with a UUID, since each task instance can have a separate configuration even if they use the same code).
SimpleDateFormat dateFormatter = new SimpleDateFormat(XdsSenderConstants.SOAP_REQUEST_DATE_TIME_FORMAT); | ||
TimeZone timeZone = TimeZone.getDefault(); | ||
dateFormatter.setTimeZone(timeZone); | ||
Date newDate = new Date(); | ||
|
||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTime(newDate); | ||
calendar.add(Calendar.DAY_OF_YEAR, -5); | ||
Date fiveDaysAgo = calendar.getTime(); | ||
|
||
RequestDate lastRequest = ccdService.getLastRequestDate(); | ||
lastRequestDate = dateFormatter.format(fiveDaysAgo); | ||
if (lastRequest != null) { | ||
lastRequestDate = dateFormatter.format(lastRequest.getRequestDate()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things here:
- The 5-days ago calculation is very arbitrary. Why that value? The process runs, by default, once an hour, so 5 days ago is likely to actually be requesting more data than the "give me 100 results" version.
- It's substantially simpler (and more correct) to do this with the
java.time
classes:
String lastRequestDateTime = /* get last date-time timestamp */
if (lastRequestDateTime == null || lastRequestDateTime.isEmpty()) {
lastRequestDateTime = DateTimeFormatter.ISO_INSTANT.format(Instant.now().minus(2, ChronoUnit.HOURS));
}
Then on the storage side, we can just persist the timestamp, e.g.,
if (success) {
saveLastRun(DateTimeFormatter.ISO_INSTANT.format(Instant.now()))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A technically better solution, though, would be not to use any guessed period and just send a single, final request with the current 100 results, and then start using the since
from there.
@@ -23,18 +27,33 @@ public class PullNotificationsTask extends AbstractTask { | |||
public void execute() { | |||
LOGGER.info("Executing " + TASK_NAME); | |||
HL7Service hl7Service = Context.getHL7Service(); | |||
Date newDate = new Date(); | |||
Boolean success = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use primitives unless you need null
;
Boolean success = true; | |
boolean success = true; |
pom.xml
Outdated
@@ -28,7 +28,7 @@ | |||
</modules> | |||
|
|||
<properties> | |||
<revision>2.4.0-SNAPSHOT</revision> | |||
<revision>2.4.1-SNAPSHOT</revision> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be a minor version bump, i.e., 2.5.0-SNAPSHOT.
No description provided.