-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rjojjr/minor-refactoring
Release v1.1.1
- Loading branch information
Showing
14 changed files
with
221 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# Even though this app is meant to be built with the included | ||
# Gradle Wrapper, this is gradle image(instead of 'openjdk:17-jdk-slim-bullseye') | ||
# is actually faster since it doesn't have | ||
# to download this gradle distribution every time you build it. | ||
FROM gradle:7.6.4-jdk17 AS builder | ||
COPY . /project | ||
WORKDIR /project | ||
RUN echo 'removing build' && (rm -rf build || echo 'no previous build exists') | ||
RUN gradle bootJar | ||
|
||
FROM openjdk:17-jdk-slim-bullseye | ||
ARG JAR_FILE=/project/build/libs/*.jar | ||
COPY --from=builder ${JAR_FILE} ./application.jar | ||
ENV TZ=America/Chicago | ||
ENV TASKS_LOCK_API_ENABLED=true | ||
ENV SPRING_PROFILES_ACTIVE=tasks-lock-api | ||
ENTRYPOINT ["java", "-jar", "application.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/rjojjr/com/github/taskslock/DestroyableTasksLockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package rjojjr.com.github.taskslock; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import rjojjr.com.github.taskslock.exception.TasksLockShutdownFailure; | ||
import rjojjr.com.github.taskslock.models.TaskLock; | ||
|
||
@Slf4j | ||
abstract class DestroyableTasksLockService extends StatefulTasksLockService { | ||
|
||
public DestroyableTasksLockService() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
log.info("Shutting down TasksLockService and releasing task-locks"); | ||
try { | ||
synchronized (dbLock) { | ||
for(TaskLock lock : taskLocks) { | ||
lock.getRelease().run(); | ||
} | ||
} | ||
log.info("Shut down TasksLockService and released task-locks"); | ||
} catch (Exception e) { | ||
log.error("error shutting down TasksLock API and releasing task-locks: {}", e.getMessage()); | ||
throw new TasksLockShutdownFailure(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/rjojjr/com/github/taskslock/StatefulTasksLockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package rjojjr.com.github.taskslock; | ||
|
||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import rjojjr.com.github.taskslock.models.TaskLock; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@NoArgsConstructor | ||
abstract class StatefulTasksLockService implements TasksLockService { | ||
|
||
protected Set<TaskLock> taskLocks = new HashSet<>(); | ||
protected final Object dbLock = new Object(); | ||
private final Object cacheLock = new Object(); | ||
|
||
protected void cacheLock(TaskLock taskLock) { | ||
synchronized (cacheLock) { | ||
log.debug("adding lock for task {} to cache contextId: {}", taskLock.getTaskName(), taskLock.getContextId()); | ||
taskLocks.add(taskLock); | ||
} | ||
} | ||
|
||
protected void removeLock(String taskName, String contextId) { | ||
synchronized (cacheLock) { | ||
log.debug("removing lock for task {} from cache contextId: {}", taskName, contextId); | ||
taskLocks = taskLocks.stream().filter(taskLock -> !taskLock.getTaskName().equals(taskName)).collect(Collectors.toSet()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.