-
Notifications
You must be signed in to change notification settings - Fork 1
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 #36 from SQUAD-D/feature#18/image-update
test
- Loading branch information
Showing
20 changed files
with
442 additions
and
168 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 |
---|---|---|
|
@@ -72,7 +72,7 @@ jobs: | |
# run: docker push haechansomg/simple-board2:was02 | ||
|
||
- name: Deploy to server | ||
uses: appleboy/[email protected].0 | ||
uses: appleboy/[email protected].3 | ||
id: deploy | ||
env: | ||
COMPOSE: "/home/ubuntu/compose/docker-compose.yml" | ||
|
@@ -85,5 +85,4 @@ jobs: | |
script: | | ||
sudo docker-compose -f $COMPOSE down --rmi all | ||
sudo docker pull haechansomg/simple-board:was01 | ||
sudo docker-compose -f $COMPOSE up -d | ||
sudo docker image prune -f | ||
sudo docker-compose -f $COMPOSE up -d |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/squad/board/config/AsyncThreadPoolConfig.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,20 @@ | ||
package squad.board.config; | ||
|
||
import java.util.concurrent.Executor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncThreadPoolConfig { | ||
|
||
@Bean | ||
public Executor asyncThreadTaskExecutor() { | ||
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); | ||
threadPoolTaskExecutor.setCorePoolSize(1); | ||
threadPoolTaskExecutor.setMaxPoolSize(1); | ||
return threadPoolTaskExecutor; | ||
} | ||
} |
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,15 @@ | ||
package squad.board.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
|
||
@Configuration | ||
public class MailConfig { | ||
|
||
@Bean | ||
public JavaMailSender javaMailSender() { | ||
return new JavaMailSenderImpl(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package squad.board.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
||
@Configuration | ||
public class TaskSchedulerConfig implements SchedulingConfigurer { | ||
@Override | ||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | ||
taskRegistrar.setScheduler(taskScheduler()); | ||
} | ||
|
||
@Bean | ||
public Executor taskScheduler() { | ||
return Executors.newScheduledThreadPool(2); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/squad/board/exception/ObjectMapperException.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,4 @@ | ||
package squad.board.exception; | ||
|
||
public class ObjectMapperException extends IllegalStateException { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package squad.board.service; | ||
|
||
import com.amazonaws.AmazonServiceException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class S3Consumer { | ||
|
||
private final S3MessageQueue messageQueue; | ||
private final S3DeadLetterQueue deadLetterQueue; | ||
private final S3Service s3Service; | ||
private final S3MailSender s3MailSender; | ||
private final String MAIL_CONTENT = "The dead letter queue has exceeded its maximum allowable size."; | ||
|
||
// @Scheduled(fixedDelay = 1000) | ||
// public void normalConsume() { | ||
// while (!messageQueue.isEmpty()) { | ||
// String uuid = messageQueue.pop(); | ||
// try { | ||
// s3Service.moveImageToOriginal(uuid); | ||
// } catch (AmazonServiceException e) { | ||
// deadLetterQueue.push(uuid); | ||
// } | ||
// } | ||
// } | ||
|
||
@Scheduled(fixedDelay = 2000) | ||
public void deadLetterConsume() { | ||
if (deadLetterQueue.isRateLimit()) { | ||
s3MailSender.send(MAIL_CONTENT); | ||
} | ||
List<String> uuids = new ArrayList<>(); | ||
while (!deadLetterQueue.isEmpty()) { | ||
uuids.add(deadLetterQueue.pop()); | ||
} | ||
messageQueue.pushAll(uuids); | ||
} | ||
} |
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,34 @@ | ||
package squad.board.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class S3DeadLetterQueue { | ||
|
||
private static final String MESSAGE_QUEUE = "s3_dead_letter"; | ||
private static final int EMPTY = 0; | ||
private static final int LIMIT = 3; | ||
private final RedisTemplate<String, Object> redisTemplate; | ||
|
||
public void pushAll(List<String> imageUUID) { | ||
for (String uuid : imageUUID) | ||
redisTemplate.opsForList().leftPushAll(MESSAGE_QUEUE, uuid); | ||
} | ||
|
||
public String pop() { | ||
return (String) redisTemplate.opsForList().rightPop(MESSAGE_QUEUE); | ||
} | ||
|
||
public boolean isRateLimit() { | ||
return redisTemplate.opsForList().size(MESSAGE_QUEUE) > LIMIT; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return redisTemplate.opsForList().size(MESSAGE_QUEUE)==EMPTY; | ||
} | ||
} |
Oops, something went wrong.