-
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.
GROUP-18 Added a Data Loader Job to automatically add active groups a…
…nd auto-disband expired groups.
- Loading branch information
Showing
15 changed files
with
519 additions
and
42 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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/grouphq/groupservice/group/demo/GroupDemoLoader.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,69 @@ | ||
package com.grouphq.groupservice.group.demo; | ||
|
||
import com.grouphq.groupservice.group.domain.groups.Group; | ||
import com.grouphq.groupservice.group.domain.groups.GroupRepository; | ||
import com.grouphq.groupservice.group.domain.groups.GroupService; | ||
import java.util.concurrent.TimeUnit; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* A Spring Job scheduler for periodically adding active groups | ||
* and auto-disbanding expired groups. | ||
*/ | ||
@Component | ||
public class GroupDemoLoader { | ||
|
||
private boolean initialStateLoaded; | ||
|
||
private final int initialGroupSize; | ||
|
||
private final int periodicGroupAdditionCount; | ||
|
||
private final GroupRepository groupRepository; | ||
|
||
private final GroupService groupService; | ||
|
||
/** | ||
* Gathers dependencies and values needed for demo loader. | ||
*/ | ||
public GroupDemoLoader(GroupService groupService, | ||
|
||
GroupRepository groupRepository, | ||
|
||
@Value("${group.loader.initial-group-size}") | ||
int initialGroupSize, | ||
|
||
@Value("${group.loader.periodic-group-addition-count}") | ||
int periodicGroupAdditionCount | ||
) { | ||
this.groupService = groupService; | ||
this.groupRepository = groupRepository; | ||
|
||
this.initialGroupSize = initialGroupSize; | ||
this.periodicGroupAdditionCount = periodicGroupAdditionCount; | ||
} | ||
|
||
@Scheduled(initialDelayString = "${group.loader.initial-group-delay}", | ||
fixedDelayString = "${group.loader.periodic-group-addition-interval}", | ||
timeUnit = TimeUnit.SECONDS) | ||
void loadGroups() { | ||
final int groupsToAdd = initialStateLoaded | ||
? periodicGroupAdditionCount : initialGroupSize; | ||
|
||
for (int i = 0; i < groupsToAdd; i++) { | ||
final Group group = groupService.generateGroup(); | ||
assert groupRepository != null; | ||
groupRepository.save(group).subscribe(); | ||
} | ||
initialStateLoaded = true; | ||
} | ||
|
||
@Scheduled(initialDelayString = "${group.expiry-checker.initial-check-delay}", | ||
fixedDelayString = "${group.expiry-checker.check-interval}", | ||
timeUnit = TimeUnit.SECONDS) | ||
void expireGroups() { | ||
groupService.expireGroups().subscribe(); | ||
} | ||
} |
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
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
Oops, something went wrong.