Skip to content

Commit

Permalink
Added isTimerServer check; changed dayOfWeek parameter to numeric (le…
Browse files Browse the repository at this point in the history
…ss error prone than alpha text) -"0" instead of "Sun"

added documentation in timers.rst, including how to reconfigure timer schedule  (caveat reconfiguring should be a one-off, tracking ejb-jar.xml files opens a can of worms IMHO). Added a sample ejb-jar file
  • Loading branch information
rtreacy committed Aug 5, 2020
1 parent 4c28c54 commit e37cf1e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
23 changes: 23 additions & 0 deletions doc/sphinx-guides/source/_static/admin/ejb-jar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.2"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<session>
<ejb-name>SavedSearchServiceBean</ejb-name>
<ejb-class>edu.harvard.iq.dataverse.search.savedsearch.SavedSearchServiceBean</ejb-class>
<session-type>Stateless</session-type>
<timer>
<schedule>
<minute>30</minute>
<hour>14</hour>
<day-of-week>2</day-of-week>
</schedule>
<timeout-method>
<method-name>makeLinksForAllSavedSearchesTimer</method-name>
</timeout-method>
</timer>
</session>
</enterprise-beans>
</ejb-jar>
20 changes: 20 additions & 0 deletions doc/sphinx-guides/source/admin/timers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ This daily job will also update all the harvestable OAI sets configured on your

This job is automatically scheduled to run at 2AM local time every night. If really necessary, it is possible (for an advanced user) to change that time by directly editing the EJB timer application table in the database.

Saved Searches Links Timer
--------------------------

This timer is created automatically from an @Schedule annotation on the makeLinksForAllSavedSearchesTimer method of the SavedSearchServiceBean when the bean is deployed.

This timer runs a weekly job to create links for any saved searches that haven't been linked yet yet.

This job is automatically scheduled to run once a week at 12:30AM local time on Sunday. If really necessary, it is possible to change that time by deploying the application war file with an ejb-jar.xml file in the WEB-INF directory of the war file. A sample file is included in doc/sphinx-guides/source/_static/admin/ejb-jar.xml - the sample would run the job every Tuesday at 2:30PM. The schedule can be modified to your choice by editing the fields in the session section. If other EJBs require some form of configuration using an ejb-jar file, there should be one ejb-jar file for the entire application, which can have different sections for each EJB. Below are instructions for the simple case of adding the ejb-jar,xml for the first time and making a custom schedule for the saved search timer.

* Create or edit dataverse/src/main/webapp/WEB-INF/ejb-jar.xml, following the example provided in dataverse/sphinx-guides/source/_static/admin/ejb-jar.xml

* Edit the parameters in the <schedule> section ejb-jar file in the WEB-INF directory to suit your preferred schedule

* the provided parameters in the sample file are <minute>, <hour>, and <dayOfWeek>; additional parameters are available

* For a complete reference for calendar expressions that can be used to schedule Timer services see: https://docs.oracle.com/javaee/7/tutorial/ejb-basicexamples004.htm

* Build and deploy the application


Known Issues
------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import edu.harvard.iq.dataverse.search.SearchException;
import edu.harvard.iq.dataverse.search.SearchFields;
import edu.harvard.iq.dataverse.search.SortBy;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class SavedSearchServiceBean {
DataverseLinkingServiceBean dataverseLinkingService;
@EJB
EjbDataverseEngine commandEngine;
@EJB
SystemConfig systemConfig;

private final String resultString = "result";

Expand Down Expand Up @@ -126,13 +129,15 @@ public SavedSearch save(SavedSearch savedSearch) {
}


@Schedule(dayOfWeek="Sun", hour="0",minute="30")
public void makeLinksForAllSavedSearchesTimer(){
logger.info("Linking saved searches");
try {
JsonObjectBuilder makeLinksForAllSavedSearches = makeLinksForAllSavedSearches(false);
} catch (SearchException | CommandException ex) {
Logger.getLogger(SavedSearchServiceBean.class.getName()).log(Level.SEVERE, null, ex);
@Schedule(dayOfWeek="0", hour="0",minute="30")
public void makeLinksForAllSavedSearchesTimer() {
if (systemConfig.isTimerServer()) {
logger.info("Linking saved searches");
try {
JsonObjectBuilder makeLinksForAllSavedSearches = makeLinksForAllSavedSearches(false);
} catch (SearchException | CommandException ex) {
Logger.getLogger(SavedSearchServiceBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

Expand Down

0 comments on commit e37cf1e

Please sign in to comment.