generated from nlnwa/go_container
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #44 from nlnwa/feat/log_confirm_messages
Log confirm messages
- Loading branch information
Showing
15 changed files
with
152 additions
and
125 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
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,42 @@ | ||
package dps | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/segmentio/kafka-go" | ||
) | ||
|
||
func ReadMessages(ctx context.Context, reader *kafka.Reader) (*KafkaResponse, error) { | ||
for { | ||
fmt.Println("Reading next message...") | ||
message, err := reader.ReadMessage(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read message: %w", err) | ||
} | ||
|
||
var dpsResponse DigitalPreservationSystemResponse | ||
|
||
err = json.Unmarshal(message.Value, &dpsResponse) | ||
if err != nil { | ||
syntaxError := new(json.SyntaxError) | ||
if errors.As(err, &syntaxError) { | ||
fmt.Printf("Could not read message at offset '%d', syntax error in message, skipping offset\n", message.Offset) | ||
continue | ||
} | ||
return nil, fmt.Errorf("failed to unmarshal json, original error: '%w'", err) | ||
} | ||
|
||
if !IsWebArchiveOwned(&dpsResponse) { | ||
fmt.Printf("Message at offset '%d' is not owned by web archive, skipping offset\n", message.Offset) | ||
continue | ||
} | ||
|
||
return &KafkaResponse{ | ||
Offset: message.Offset, | ||
Key: string(message.Key), | ||
DPSResponse: dpsResponse, | ||
}, nil | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package sendImplementation | ||
package dps | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package sendImplementation | ||
package dps | ||
|
||
import ( | ||
"hermetic/internal/submission_information_package" | ||
|
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,28 @@ | ||
package dps | ||
|
||
type Check struct { | ||
Status string | ||
Message string | ||
Reason string | ||
File string | ||
} | ||
|
||
type DigitalPreservationSystemResponse struct { | ||
Date string | ||
Identifier string | ||
Urn string | ||
Path string | ||
ContentType string | ||
ContentCategory string | ||
Checks []Check | ||
} | ||
|
||
type KafkaResponse struct { | ||
Offset int64 | ||
Key string | ||
DPSResponse DigitalPreservationSystemResponse | ||
} | ||
|
||
func IsWebArchiveOwned(message *DigitalPreservationSystemResponse) bool { | ||
return message.ContentCategory == "nettarkiv" | ||
} |
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package confirmImplmentation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/segmentio/kafka-go" | ||
"hermetic/internal/dps" | ||
) | ||
|
||
func Verify(confirmTopicName string) error { | ||
fmt.Printf("Reading messages from topic '%s'\n", confirmTopicName) | ||
fmt.Printf("This command is not implemented yet\n" + | ||
"Aims to solve issue https://github.com/nlnwa/hermetic/issues/3 ") | ||
return nil | ||
func ReadConfirmTopic(ctx context.Context, reader *kafka.Reader) error { | ||
for { | ||
response, err := dps.ReadMessages(ctx, reader) | ||
if err != nil { | ||
return fmt.Errorf("failed to read message from confirm-topic: `%w`", err) | ||
} | ||
fmt.Printf("SIP successfully preserved: %+v\n", response) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.