Skip to content

Commit

Permalink
Fix scheduled tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed Aug 10, 2023
1 parent 5af39d2 commit 9698ab6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
6 changes: 4 additions & 2 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ knowledgeBase:
lists:
service: https://lists.ala.org.au/ws
items: /speciesListItems/{0}?includeKVP=true&max={1}&offset={2}
add: /createRecord
remove: /deleteRecord
add: /createItem
remove: /deleteItem
# If attribution entry is null, the default is used
naming:
service: https://namematching-ws.ala.org.au
Expand Down Expand Up @@ -276,6 +276,8 @@ import:
sequence: collectory,taxonomy-all,vernacular,denormalise,layers,regions,localities,conservation-lists,wordpress,knowledgebase,favourites,weights,link-identifiers,images,occurrences,hidden-images,wiki-urls,suggest-index,swap
sequenceDaily: conservation-lists,wordpress,knowledgebase,favourites,suggest-index,swap
sequenceWeekly: images,hidden-images,wiki-urls,occurrences,layers,regions,localities,suggest-index,swap
# enable daily and weekly tasks
enableTasks: false
# run daily sequence on this hour
dailyRunHour: 2
# run weekly sequence on this day (6 == Saturday)
Expand Down
40 changes: 21 additions & 19 deletions grails-app/init/bie/index/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ class BootStrap {
"classpath:messages"
)

Date weeklyStart = new Date(hours: Integer.parseInt(Holders.config.import.dailyRunHour as String))
while(weeklyStart.day != Integer.parseInt(Holders.config.import.weeklyRunDay as String) || weeklyStart.before(new Date())) {
weeklyStart = DateUtils.addDays(weeklyStart, 1)
}

threadPoolTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
void run() {
importService.importAll(importService.importWeeklySequence, false)
if (Holders.config.import.enableTasks) {
Date weeklyStart = new Date(hours: Integer.parseInt(Holders.config.import.dailyRunHour as String))
while (weeklyStart.day != Integer.parseInt(Holders.config.import.weeklyRunDay as String) || weeklyStart.before(new Date())) {
weeklyStart = DateUtils.addDays(weeklyStart, 1)
}
}, weeklyStart, 7*24*60*60*1000)

Date dailyStart = new Date(hours: Integer.parseInt(Holders.config.import.dailyRunHour as String))
while(dailyStart.before(new Date())) {
dailyStart = DateUtils.addDays(dailyStart, 1)
}
threadPoolTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
void run() {
importService.importAll(importService.importWeeklySequence, false)
}
}, weeklyStart, 7 * 24 * 60 * 60 * 1000)

threadPoolTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
void run() {
importService.importAll(importService.importDailySequence, false)
Date dailyStart = new Date(hours: Integer.parseInt(Holders.config.import.dailyRunHour as String))
while (dailyStart.before(new Date())) {
dailyStart = DateUtils.addDays(dailyStart, 1)
}
}, dailyStart, 24*60*60*1000)

threadPoolTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
void run() {
importService.importAll(importService.importDailySequence, false)
}
}, dailyStart, 24 * 60 * 60 * 1000)
}
}
def destroy = {
}
Expand Down
7 changes: 4 additions & 3 deletions grails-app/services/au/org/ala/bie/ListService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class ListService {

def add(listDr, name, guid, extraField, extraValue) {
def url = new URL(grailsApplication.config.lists.service + grailsApplication.config.lists.add)
def data = [druid: listDr, guid: guid, rawScientificName: name]
data[extraField] = extraValue
webService.get(url.toString(), data, ContentType.APPLICATION_JSON, true, false, [:])
def query = [druid: listDr]
def body = [guid: guid, rawScientificName: name]
body[extraField] = extraValue
webService.post(url.toString(), body, query, ContentType.APPLICATION_JSON, true, false, [:])
}

def remove(listDr, guid) {
Expand Down

0 comments on commit 9698ab6

Please sign in to comment.