Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
46
Issues
46
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
697913c6
Commit
697913c6
authored
Nov 09, 2018
by
Viacheslav Pavlov
Committed by
Matija Obreza
Nov 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@Scheduled KPI execution
- increased max lock duration, fixed lockProvider bean init
parent
99ec18fb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
0 deletions
+103
-0
pom.xml
pom.xml
+10
-0
src/main/java/org/genesys2/server/service/worker/KpiScheduledExecutor.java
.../genesys2/server/service/worker/KpiScheduledExecutor.java
+85
-0
src/main/java/org/genesys2/spring/config/HazelcastConfig.java
...main/java/org/genesys2/spring/config/HazelcastConfig.java
+7
-0
src/main/resources/log4j.properties
src/main/resources/log4j.properties
+1
-0
No files found.
pom.xml
View file @
697913c6
...
...
@@ -308,6 +308,16 @@
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
net.javacrumbs.shedlock
</groupId>
<artifactId>
shedlock-spring
</artifactId>
<version>
2.1.0
</version>
</dependency>
<dependency>
<groupId>
net.javacrumbs.shedlock
</groupId>
<artifactId>
shedlock-provider-hazelcast
</artifactId>
<version>
0.18.2
</version>
</dependency>
<dependency>
<groupId>
com.querydsl
</groupId>
<artifactId>
querydsl-jpa
</artifactId>
...
...
src/main/java/org/genesys2/server/service/worker/KpiScheduledExecutor.java
0 → 100644
View file @
697913c6
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys2.server.service.worker
;
import
net.javacrumbs.shedlock.core.SchedulerLock
;
import
org.apache.commons.lang3.time.StopWatch
;
import
org.genesys2.server.model.kpi.Execution
;
import
org.genesys2.server.security.AsAdminInvoker
;
import
org.genesys2.server.service.KPIService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* Component to periodically run all KPI Executions
*/
@Component
public
class
KpiScheduledExecutor
{
/** The Constant LOG. */
public
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
KpiScheduledExecutor
.
class
);
/** The kpi service. */
@Autowired
private
KPIService
kpiService
;
/** The as admin invoker. */
@Autowired
protected
AsAdminInvoker
asAdminInvoker
;
/**
* Run executions.
*
* @throws Exception the exception
*/
@Scheduled
(
cron
=
"0 0 3 * * *"
)
// @Scheduled(cron = "0 0/10 * * * *") // Test every 10min
@SchedulerLock
(
name
=
"org.genesys2.server.service.worker.KpiExecutor"
)
public
void
runExecutions
()
throws
Exception
{
LOG
.
info
(
"Started scheduled executions run"
);
StopWatch
stopWatch
=
StopWatch
.
createStarted
();
asAdminInvoker
.
invoke
(()
->
{
final
int
chunkSize
=
50
;
int
page
=
0
;
Page
<
Execution
>
executions
;
do
{
executions
=
kpiService
.
listExecutions
(
new
PageRequest
(
page
,
chunkSize
));
for
(
Execution
ex
:
executions
.
getContent
())
{
try
{
LOG
.
info
(
"Started execution {} after {}ms"
,
ex
.
getName
(),
stopWatch
.
getTime
());
kpiService
.
execute
(
ex
);
LOG
.
info
(
"Execution {} successful after {}ms"
,
ex
.
getName
(),
stopWatch
.
getTime
());
}
catch
(
Throwable
e
)
{
LOG
.
error
(
"Error running KPI Execution {}: {}"
,
ex
.
getName
(),
e
.
getMessage
(),
e
);
}
}
page
++;
}
while
(
executions
.
getTotalPages
()
<
page
);
if
(
executions
!=
null
)
{
LOG
.
info
(
"Run of {} executions ended successfully after {}ms."
,
executions
.
getTotalElements
(),
stopWatch
.
getTime
());
}
return
true
;
});
}
}
src/main/java/org/genesys2/spring/config/HazelcastConfig.java
View file @
697913c6
...
...
@@ -23,6 +23,8 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.Properties
;
import
net.javacrumbs.shedlock.provider.hazelcast.HazelcastLockProvider
;
import
net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock
;
import
org.apache.commons.lang3.StringUtils
;
import
org.genesys.blocks.security.lockout.AccountLockoutManager.AttemptStatistics
;
import
org.genesys2.spring.hazelcast.HazelcastCacheRegionFactoryWrapper
;
...
...
@@ -59,6 +61,7 @@ import com.hazelcast.web.spring.SpringAwareWebFilter;
@Configuration
@EnableCaching
@EnableSchedulerLock
(
defaultLockAtMostFor
=
"PT15M"
)
public
abstract
class
HazelcastConfig
{
protected
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HazelcastConfig
.
class
);
...
...
@@ -406,4 +409,8 @@ public abstract class HazelcastConfig {
return
properties
;
}
@Bean
public
HazelcastLockProvider
lockProvider
(
HazelcastInstance
hazelcastInstance
)
{
return
new
HazelcastLockProvider
(
hazelcastInstance
);
}
}
src/main/resources/log4j.properties
View file @
697913c6
...
...
@@ -29,6 +29,7 @@ log4j.rootLogger=error, stdout
log4j.category.org.genesys2
=
warn
log4j.category.org.genesys
=
warn
log4j.category.org.genesys2.server.api
=
warn
log4j.category.org.genesys2.server.service.worker.KpiScheduledExecutor
=
info
log4j.category.liquibase
=
debug
#log4j.category.springfox=trace
#log4j.category.org.genesys2.server.servlet.controller=debug
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment