Skip to content

Commit e8a6b66

Browse files
committed
Allow GeneticCalculationsJob to optionally run on specified day of the week
1 parent 4f787f8 commit e8a6b66

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

ehr/resources/web/ehr/panel/GeneticCalculationSettingsPanel.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Ext4.define('EHR.panel.GeneticCalculationSettingsPanel', {
77
extend: 'Ext.panel.Panel',
88

99
initComponent: function(){
10+
Ext4.QuickTips.init();
1011
Ext4.apply(this, {
1112
//width: 550,
1213
border: false,
@@ -48,6 +49,15 @@ Ext4.define('EHR.panel.GeneticCalculationSettingsPanel', {
4849
fieldLabel: 'Hour Of Day',
4950
itemId: 'hourOfDay',
5051
width: 400
52+
},{
53+
xtype: 'numberfield',
54+
hideTrigger: true,
55+
fieldLabel: 'Day of Week',
56+
itemId: 'dayOfWeek',
57+
helpPopup: 'If provided, the job will run on the specified day of the week (1-7 or Sun-Sat). If blank, it will run each day.',
58+
width: 400,
59+
minValue: 1,
60+
maxValue: 7
5161
},{
5262
xtype: 'textfield',
5363
fieldLabel: 'Container Path',
@@ -96,6 +106,7 @@ Ext4.define('EHR.panel.GeneticCalculationSettingsPanel', {
96106
this.down('#isScheduled').setValue(results.isScheduled);
97107
this.down('#enabled').setValue(results.enabled);
98108
this.down('#hourOfDay').setValue(results.hourOfDay);
109+
this.down('#dayOfWeek').setValue(results.dayOfWeek);
99110
this.down('#containerPath').setValue(results.containerPath);
100111
this.down('#kinshipValidation').setValue(results.kinshipValidation);
101112
this.down('#allowImportDuringBusinessHours').setValue(results.allowImportDuringBusinessHours)
@@ -109,6 +120,7 @@ Ext4.define('EHR.panel.GeneticCalculationSettingsPanel', {
109120
containerPath: this.down('#containerPath').getValue(),
110121
enabled: this.down('#enabled').getValue(),
111122
hourOfDay: this.down('#hourOfDay').getValue(),
123+
dayOfWeek: this.down('#dayOfWeek').getValue(),
112124
kinshipValidation: this.down('#kinshipValidation').getValue(),
113125
allowImportDuringBusinessHours: this.down('#allowImportDuringBusinessHours').getValue()
114126
},

ehr/src/org/labkey/ehr/EHRController.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public ApiResponse execute(ScheduleGeneticCalculationForm form, BindException er
640640
errors.reject(ERROR_MSG, "Unable to find container for path: " + form.getContainerPath());
641641
return null;
642642
}
643-
GeneticCalculationsJob.setProperties(form.isEnabled(), c, form.getHourOfDay(), form.isKinshipValidation(), form.isAllowImportDuringBusinessHours());
643+
GeneticCalculationsJob.setProperties(form.isEnabled(), c, form.getHourOfDay(), form.getDayOfWeek(), form.isKinshipValidation(), form.isAllowImportDuringBusinessHours());
644644

645645
return new ApiSimpleResponse("success", true);
646646
}
@@ -758,6 +758,7 @@ public static class ScheduleGeneticCalculationForm
758758
private boolean _enabled;
759759
private String containerPath;
760760
private int hourOfDay;
761+
private Integer dayOfWeek;
761762

762763
private boolean _kinshipValidation;
763764
private boolean _allowImportDuringBusinessHours;
@@ -792,6 +793,16 @@ public void setHourOfDay(int hourOfDay)
792793
this.hourOfDay = hourOfDay;
793794
}
794795

796+
public Integer getDayOfWeek()
797+
{
798+
return dayOfWeek;
799+
}
800+
801+
public void setDayOfWeek(Integer dayOfWeek)
802+
{
803+
this.dayOfWeek = dayOfWeek;
804+
}
805+
795806
public boolean isKinshipValidation()
796807
{
797808
return _kinshipValidation;
@@ -828,6 +839,7 @@ public ApiResponse execute(ScheduleGeneticCalculationForm form, BindException er
828839
ret.put("isScheduled", GeneticCalculationsJob.isScheduled());
829840
ret.put("enabled", GeneticCalculationsJob.isEnabled());
830841
ret.put("hourOfDay", GeneticCalculationsJob.getHourOfDay());
842+
ret.put("dayOfWeek", GeneticCalculationsJob.getDayOfWeek());
831843
ret.put("kinshipValidation", GeneticCalculationsJob.isKinshipValidation());
832844
ret.put("allowImportDuringBusinessHours", GeneticCalculationsJob.isAllowImportDuringBusinessHours());
833845

ehr/src/org/labkey/ehr/pipeline/GeneticCalculationsJob.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ public static void schedule()
9797
if (hour == null)
9898
hour = 2;
9999

100+
Integer day = getDayOfWeek();
101+
100102
JobDetail job = JobBuilder.newJob(GeneticCalculationsJob.class)
101103
.withIdentity(GeneticCalculationsJob.class.getCanonicalName())
102104
.build();
103105

104106
Trigger trigger = TriggerBuilder.newTrigger()
105107
.withIdentity(GeneticCalculationsJob.class.getCanonicalName())
106-
.withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(hour, 0))
108+
.withSchedule(day == null ? CronScheduleBuilder.dailyAtHourAndMinute(hour, 0) : CronScheduleBuilder.weeklyOnDayAndHourAndMinute(day, hour, 0))
107109
.forJob(job)
108110
.build();
109111

@@ -174,12 +176,23 @@ public static Integer getHourOfDay()
174176
return null;
175177
}
176178

177-
public static void setProperties(Boolean isEnabled, Container c, Integer hourOfDay, Boolean isKinshipValidation, Boolean allowImportDuringBusinessHours)
179+
public static Integer getDayOfWeek()
180+
{
181+
Map<String, String> saved = PropertyManager.getProperties(GENETICCALCULATIONS_PROPERTY_DOMAIN);
182+
183+
if (saved.containsKey("dayOfWeek") & saved.get("dayOfWeek") != null)
184+
return Integer.parseInt(saved.get("dayOfWeek"));
185+
186+
return null;
187+
}
188+
189+
public static void setProperties(Boolean isEnabled, Container c, Integer hourOfDay, @Nullable Integer dayOfWeek, Boolean isKinshipValidation, Boolean allowImportDuringBusinessHours)
178190
{
179191
WritablePropertyMap props = PropertyManager.getWritableProperties(GENETICCALCULATIONS_PROPERTY_DOMAIN, true);
180192
props.put("enabled", isEnabled.toString());
181193
props.put("container", c.getId());
182194
props.put("hourOfDay", hourOfDay.toString());
195+
props.put("dayOfWeek", dayOfWeek == null ? null : dayOfWeek.toString());
183196
props.put("kinshipValidation", isKinshipValidation.toString());
184197
props.put("allowImportDuringBusinessHours", allowImportDuringBusinessHours.toString());
185198
props.save();

0 commit comments

Comments
 (0)