I have a question about EO refresh. I have a component where I show the list of running and completed jobs (reports) and since some jobs might be running, I want to use AjaxPing to refresh the page every 5 seconds so that users don't have to click on a link or button to refresh the page.
The list is built with: public NSArray<ReportTask> reportsForCurrentUser() { return ReportTask.fetchReportTasks(editingContext(), ReportTask.USER.eq(((Session)session()).user()), ReportTask.START_TIME.descs()); }
The editing context have a 1 second timestamp:
protected EOEditingContext editingContext() { if (_editingContext == null) { _editingContext = ERXEC.newEditingContext(); _editingContext.setFetchTimestamp(1000); } return _editingContext; }
And I have a method, countOfRunningJobs, that fetch the list of currently running or pending jobs. I use that method to return the number of running jobs and use it as the "cacheKey" binding for AjaxPing.
public int countOfRunningJobs() { EOQualifier qualifier = ReportTask.USER.eq(((Session)session()).user()).and(ReportTask.STATUS.notIn(new NSArray<ReportTaskStatus>(new ReportTaskStatus[] { ReportTaskStatus.COMPLETED, ReportTaskStatus.STOPPED } ))); NSArray<ReportTask> runningTasks = ReportTask.fetchReportTasks(editingContext(), qualifier, null); for (ReportTask task: runningTasks) { editingContext().refreshObject(task); NSLog.out.appendln(task.status()); } return ReportTask.fetchReportTasks(editingContext(), qualifier, null).count(); }
That logic is ok, if I print the integer in the component, the value is ok (eg, if I have a running job, count is 1, when the job is completed, count is 0). But the "task" EO is NOT updated after the refresh, even if in the database, the status was changed to "COMPLETED", the NSLog call returns "RUNNING". I do see a SELECT being done to fetch the task details, so it look it's EOF who doesn't want to refresh the object, even if the timestamp is low.
What I'm doing wrong?
|