From 9698ab6c170dfac167734edd01f515c816af2867 Mon Sep 17 00:00:00 2001 From: Adam Collins Date: Fri, 11 Aug 2023 09:34:34 +1000 Subject: [PATCH] Fix scheduled tasks --- grails-app/conf/application.yml | 6 ++- grails-app/init/bie/index/BootStrap.groovy | 40 ++++++++++--------- .../au/org/ala/bie/ListService.groovy | 7 ++-- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/grails-app/conf/application.yml b/grails-app/conf/application.yml index 2ce4970..40f1926 100644 --- a/grails-app/conf/application.yml +++ b/grails-app/conf/application.yml @@ -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 @@ -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) diff --git a/grails-app/init/bie/index/BootStrap.groovy b/grails-app/init/bie/index/BootStrap.groovy index 76cb3ec..a8338c1 100644 --- a/grails-app/init/bie/index/BootStrap.groovy +++ b/grails-app/init/bie/index/BootStrap.groovy @@ -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 = { } diff --git a/grails-app/services/au/org/ala/bie/ListService.groovy b/grails-app/services/au/org/ala/bie/ListService.groovy index 5235e3f..1f9a3e7 100644 --- a/grails-app/services/au/org/ala/bie/ListService.groovy +++ b/grails-app/services/au/org/ala/bie/ListService.groovy @@ -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) {