Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ public Object execute(EmailCronForm form, BindException errors) throws Exception
case "start":
// if already started
if (scheduler.checkExists(jobKeyEmail)) {
saveEmailEnabled(true);
res.put("Message", "Job already exists");
res.put("Response", "true");
return new ApiSimpleResponse(res);
Expand All @@ -1424,6 +1425,7 @@ public Object execute(EmailCronForm form, BindException errors) throws Exception
scheduler = start(scheduler, jobKeyEmail); // start
// ensure job exists after started
if (scheduler.checkExists(jobKeyEmail)) {
saveEmailEnabled(true);
res.put("Message", "Job Created");
res.put("Response", "true");
} else {
Expand All @@ -1434,6 +1436,7 @@ public Object execute(EmailCronForm form, BindException errors) throws Exception
case "stop":
scheduler.deleteJob(jobKeyEmail);
if (!scheduler.checkExists(jobKeyEmail)) {
saveEmailEnabled(false);
res.put("Message", "Job successfully removed");
res.put("Response", "false");
} else {
Expand Down Expand Up @@ -1490,6 +1493,12 @@ public Object execute(EmailCronForm form, BindException errors) throws Exception
return new ApiSimpleResponse(res);
}

private void saveEmailEnabled(boolean enabled)
{
TestResultsModule.setEmailEnabled(enabled);
_log.info("The daily test results email was {} by {}", enabled ? "enabled" : "disabled", getUser().getEmail());
}

@NotNull
public static Scheduler start(Scheduler scheduler, JobKey jobKeyEmail) throws SchedulerException
{
Expand Down
24 changes: 24 additions & 0 deletions testresults/src/org/labkey/testresults/TestResultsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.data.PropertyManager;
import org.labkey.api.module.DefaultModule;
import org.labkey.api.module.ModuleContext;
import org.labkey.api.security.Directive;
Expand Down Expand Up @@ -49,6 +50,9 @@ public class TestResultsModule extends DefaultModule
public static final String JOB_NAME = "TestResultsEmailTrigger";
public static final String JOB_GROUP = "TestResultsGroup";

private static final String TESTRESULTS_EMAIL_PROPS = "TestResultsEmail";
private static final String PROP_EMAIL_ENABLED = "enabled";

// for saving
public static final String TR_VIEW = "testresults-view";

Expand Down Expand Up @@ -120,6 +124,11 @@ public Set<String> getSchemaNames()
@NotNull
public void startBackgroundThreads()
{
if (!isEmailEnabled())
{
LOG.info("The daily test results email is not enabled. A site admin can start it on the training data page.");
return;
}
try
{
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
Expand All @@ -132,4 +141,19 @@ public void startBackgroundThreads()
}

}

/**
* Returns true if a site admin has started the daily email. A server with no saved setting returns false.
*/
public static boolean isEmailEnabled()
{
return Boolean.parseBoolean(PropertyManager.getProperties(TESTRESULTS_EMAIL_PROPS).get(PROP_EMAIL_ENABLED));
}

public static void setEmailEnabled(boolean enabled)
{
PropertyManager.WritablePropertyMap map = PropertyManager.getWritableProperties(TESTRESULTS_EMAIL_PROPS, true);
map.put(PROP_EMAIL_ENABLED, String.valueOf(enabled));
map.save();
}
}