Skip to content

Commit

Permalink
Set pseudorandom delay seconds for DailyCheckRequestQueue messages
Browse files Browse the repository at this point in the history
  • Loading branch information
binchoo committed Oct 22, 2022
1 parent 7e42e6a commit bcedbf0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions PaimonGanyu/paimonganyu-app/paimonganyu-skill/samconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ version = 0.1
[default.deploy]
[default.deploy.parameters]
stack_name = "paimonganyu-skill"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-idkhpdkh78w2"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-3t80l0g3f3ma"
s3_prefix = "paimonganyu-skill"
region = "ap-northeast-2"
profile = "pgtest"
profile = "pgprod"
capabilities = "CAPABILITY_IAM"
parameter_overrides = "Env=\"test\" UseALB=\"False\""
parameter_overrides = "Env=\"prod\" UseALB=\"False\""
image_repositories = []
disable_rollback = true
6 changes: 3 additions & 3 deletions PaimonGanyu/paimonganyu-app/paimonganyu/samconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ version = 0.1
[default.deploy]
[default.deploy.parameters]
stack_name = "paimonganyu"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-idkhpdkh78w2"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-3t80l0g3f3ma"
s3_prefix = "paimonganyu"
region = "ap-northeast-2"
profile = "pgtest"
profile = "pgprod"
capabilities = "CAPABILITY_IAM"
image_repositories = []
parameter_overrides = "Env=\"test\""
parameter_overrides = "Env=\"prod\""
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import com.amazonaws.services.lambda.runtime.events.ScheduledEvent;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.binchoo.paimonganyu.dailycheck.driving.DailyCheckPort;
import org.binchoo.paimonganyu.hoyopass.driven.UserHoyopassCrudPort;
Expand All @@ -17,6 +18,7 @@

import java.util.List;
import java.util.Objects;
import java.util.Random;

public class DailyCheckBatchRequesterLambda {

Expand Down Expand Up @@ -59,9 +61,13 @@ private void lookupDependencies(GenericApplicationContext context) {
}

public void handler(ScheduledEvent event) {
Random r = new Random();
hoyopassCrud.findAll().stream().map(DailyCheckTaskSpec::specify)
.flatMap(List::stream)
.filter(task-> !dailyCheck.hasCheckedInToday(task.getBotUserId(), task.getLtuid()))
.forEach(task-> sqsClient.sendMessage(DAILYCHECK_QUEUE_URL, task.asJson(objectMapper)));
.forEach(task-> sqsClient.sendMessage(new SendMessageRequest()
.withQueueUrl(DAILYCHECK_QUEUE_URL)
.withMessageBody(task.asJson(objectMapper))
.withDelaySeconds(r.nextInt() % 20 + 1)));
}
}
5 changes: 2 additions & 3 deletions PaimonGanyu/paimonganyu-app/paimonganyu/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ Resources:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 60
DelaySeconds: 7
RedrivePolicy:
maxReceiveCount: 3
maxReceiveCount: 2
deadLetterTargetArn: !GetAtt DailyCheckRequestDLQ.Arn

DailyCheckRequestDLQ:
Expand Down Expand Up @@ -217,7 +216,7 @@ Resources:
FirstDailyCheckEvent:
Type: Schedule
Properties:
Schedule: 'cron(1/8 16 ? * * *)' # everyday 01:[01, 09, ..., 57]AM (Seoul)
Schedule: 'cron(1/11 16 ? * * *)' # everyday 01:[01, 12, ..., 56]AM (Seoul)
Name: first-dailycheck
Description: Do batch daily check-in serveral times around 01:00AM
Enabled: true
Expand Down

0 comments on commit bcedbf0

Please sign in to comment.