Skip to content

Commit

Permalink
Add timer for saved searches IQSS#6910
Browse files Browse the repository at this point in the history
The timer method wraps the makeLinksForAllSavedSearches in a no-param method returning void with the @schedule annotation.
The timer is sheduled to run once a week on Sunday at 12:30 AM. If we decide a different schedule is better in general, we
should adjust thiis in the code before release. In special cases the schedule can be modified using and ejb-jar.xml file
of the form(for ex Tuesday 2:30 PM) :

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
         version = "3.1"
         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>Tue</day-of-week>
                </schedule>
                <timeout-method>
                    <method-name>makeLinksForAllSavedSearchesTimer</method-name>
                </timeout-method>
            </timer>
        </session>
    </enterprise-beans>
</ejb-jar>
  • Loading branch information
rtreacy committed Jul 31, 2020
1 parent c9ec158 commit 4c28c54
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import edu.harvard.iq.dataverse.search.SortBy;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.json.Json;
Expand Down Expand Up @@ -122,6 +124,17 @@ public SavedSearch save(SavedSearch savedSearch) {
return em.merge(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);
}
}

public JsonObjectBuilder makeLinksForAllSavedSearches(boolean debugFlag) throws SearchException, CommandException {
JsonObjectBuilder response = Json.createObjectBuilder();
Expand Down

0 comments on commit 4c28c54

Please sign in to comment.