-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(amqp): Using exclusive pattern around concurrent file access
Signed-off-by: Vincent Boutour <[email protected]>
- Loading branch information
Showing
25 changed files
with
194 additions
and
165 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 |
---|---|---|
|
@@ -288,6 +288,8 @@ Usage of fibr: | |
[owasp] Content-Security-Policy {FIBR_CSP} (default "default-src 'self'; base-uri 'self'; script-src 'self' 'httputils-nonce' unpkg.com/[email protected]/dist-cjs/ unpkg.com/[email protected]/dist/ unpkg.com/[email protected]/; style-src 'self' 'httputils-nonce' unpkg.com/[email protected]/dist/ unpkg.com/[email protected]/; img-src 'self' data: a.tile.openstreetmap.org b.tile.openstreetmap.org c.tile.openstreetmap.org") | ||
-exifAmqpExchange string | ||
[exif] AMQP Exchange Name {FIBR_EXIF_AMQP_EXCHANGE} (default "fibr") | ||
-exifAmqpExclusiveRoutingKey string | ||
[exif] AMQP Routing Key for exclusive lock on default exchange {FIBR_EXIF_AMQP_EXCLUSIVE_ROUTING_KEY} (default "fibr.semaphore.exif") | ||
-exifAmqpRoutingKey string | ||
[exif] AMQP Routing Key for exif {FIBR_EXIF_AMQP_ROUTING_KEY} (default "exif_input") | ||
-exifDirectAccess | ||
|
@@ -355,7 +357,7 @@ Usage of fibr: | |
-publicURL string | ||
Public URL {FIBR_PUBLIC_URL} (default "http://localhost:1080") | ||
-readTimeout duration | ||
[server] Read Timeout {FIBR_READ_TIMEOUT} (default 2m0s) | ||
[server] Read Timeout {FIBR_READ_TIMEOUT} (default 1m0s) | ||
-redisAddress string | ||
[redis] Redis Address fqdn:port (blank to disable) {FIBR_REDIS_ADDRESS} | ||
-redisAlias string | ||
|
@@ -437,7 +439,7 @@ Usage of fibr: | |
-webhookSecret string | ||
[webhook] Secret for HMAC Signature {FIBR_WEBHOOK_SECRET} | ||
-writeTimeout duration | ||
[server] Write Timeout {FIBR_WRITE_TIMEOUT} (default 2m0s) | ||
[server] Write Timeout {FIBR_WRITE_TIMEOUT} (default 1m0s) | ||
``` | ||
# Caveats | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package exif | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
absto "github.com/ViBiOh/absto/pkg/model" | ||
exas "github.com/ViBiOh/exas/pkg/model" | ||
"github.com/ViBiOh/fibr/pkg/provider" | ||
"github.com/ViBiOh/httputils/v4/pkg/logger" | ||
) | ||
|
||
type MetadataOption func(provider.Metadata) provider.Metadata | ||
|
||
func WithExif(exif exas.Exif) MetadataOption { | ||
return func(instance provider.Metadata) provider.Metadata { | ||
instance.Exif = exif | ||
|
||
return instance | ||
} | ||
} | ||
|
||
func WithDescription(description string) MetadataOption { | ||
return func(instance provider.Metadata) provider.Metadata { | ||
instance.Description = description | ||
|
||
return instance | ||
} | ||
} | ||
|
||
func (a App) update(ctx context.Context, item absto.Item, opts ...MetadataOption) (provider.Metadata, error) { | ||
var metadata provider.Metadata | ||
|
||
return metadata, provider.Exclusive(ctx, a.amqpClient, a.amqpExclusiveRoutingKey, func(ctx context.Context) error { | ||
var err error | ||
|
||
metadata, err := a.GetMetadataFor(ctx, item) | ||
if err != nil && !absto.IsNotExist(err) { | ||
logger.WithField("item", item.Pathname).Error("load exif: %s", err) | ||
} | ||
|
||
for _, opt := range opts { | ||
metadata = opt(metadata) | ||
} | ||
|
||
if err = a.exifCacheApp.EvictOnSuccess(ctx, item, a.saveMetadata(ctx, item, metadata)); err != nil { | ||
return fmt.Errorf("save exif: %w", err) | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func (a App) UpdateDescription(ctx context.Context, item absto.Item, description string) error { | ||
_, err := a.update(ctx, item, WithDescription(description)) | ||
return err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.