Skip to content
Snippets Groups Projects
Commit 8a924a01 authored by Jan Semmelink's avatar Jan Semmelink
Browse files

In cron, read env CRON_MESSAGE_TYPE for routing

parent 80f3ac7f
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@ package cron
import (
"context"
"math/rand"
"os"
"time"
"github.com/aws/aws-lambda-go/lambdacontext"
......@@ -16,9 +17,17 @@ func (cron Cron) Handler(lambdaCtx context.Context) (err error) {
lc, _ := lambdacontext.FromContext(lambdaCtx)
requestID := lc.AwsRequestID
cronName, cronFunc := cron.router.Route(lc.InvokedFunctionArn)
//if env CRON_MESSAGE_TYPE is defined, this instance only process that type
//if not, try to use ARN from the event context which allows one instance to
//call any handler
routeKey := os.Getenv("CRON_MESSAGE_TYPE")
if routeKey == "" {
routeKey = lc.InvokedFunctionArn
}
cronName, cronFunc := cron.router.Route(routeKey)
if cronFunc == nil {
return errors.Errorf("request-id:%s unknown cron function(%s)", requestID, lc.InvokedFunctionArn)
return errors.Errorf("request-id:%s unknown cron function(%s)", requestID, routeKey)
}
//got a handler, prepare to run:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment