-
Notifications
You must be signed in to change notification settings - Fork 45
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 #406 from LerianStudio/develop
merge: develop to main v1.34.0
- Loading branch information
Showing
24 changed files
with
243 additions
and
93 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
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 |
---|---|---|
|
@@ -62,5 +62,5 @@ branches: | |
- main | ||
- name: develop | ||
prerelease: "beta" | ||
- name: hotfix/** | ||
- name: hotfix/* | ||
prerelease: "hf" |
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
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
10 changes: 6 additions & 4 deletions
10
components/transaction/internal/adapters/redis/redis.mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
components/transaction/internal/services/command/create-idempotency-key.go
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 command | ||
|
||
import ( | ||
"context" | ||
"github.com/LerianStudio/midaz/pkg" | ||
"github.com/LerianStudio/midaz/pkg/constant" | ||
"github.com/LerianStudio/midaz/pkg/mopentelemetry" | ||
"github.com/google/uuid" | ||
"time" | ||
) | ||
|
||
func (uc *UseCase) CreateOrCheckIdempotencyKey(ctx context.Context, organizationID, ledgerID uuid.UUID, key, hash string, ttl time.Duration) error { | ||
logger := pkg.NewLoggerFromContext(ctx) | ||
tracer := pkg.NewTracerFromContext(ctx) | ||
|
||
ctx, span := tracer.Start(ctx, "command.create-idempotency-key") | ||
defer span.End() | ||
|
||
logger.Infof("Trying to create or check idempotency key in redis") | ||
|
||
if key == "" { | ||
key = hash | ||
} | ||
|
||
internalKey := organizationID.String() + ":" + ledgerID.String() + ":" + key | ||
|
||
value, err := uc.RedisRepo.Get(ctx, internalKey) | ||
if err != nil { | ||
logger.Error("Error to get idempotency key on redis failed:", err.Error()) | ||
} | ||
|
||
if value == "" { | ||
err = uc.RedisRepo.Set(ctx, internalKey, hash, ttl) | ||
if err != nil { | ||
logger.Error("Error to set idempotency key on redis failed:", err.Error()) | ||
} | ||
} else { | ||
err = pkg.ValidateBusinessError(constant.ErrIdempotencyKey, "CreateOrCheckIdempotencyKey", key) | ||
|
||
mopentelemetry.HandleSpanError(&span, "Failed exists value on redis with this key", err) | ||
|
||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.