Skip to content

Commit

Permalink
fix(aider): some messups in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Jan 13, 2025
1 parent 423d374 commit cfadfd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions server/legalhold/legal_hold.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const PostExportBatchLimit = 10000
const executionGlobalTimeout = 120 * 60 * 1000 // 2 hours
const executionGlobalTimeout = 48 * time.Hour

// Execution represents one execution of a LegalHold, i.e. a daily (or other duration)
// batch process to hold all data relating to that particular LegalHold. It is defined by the
Expand Down Expand Up @@ -62,14 +62,16 @@ func NewExecution(legalHold model.LegalHold, papi plugin.API, store *sqlstore.SQ

// Execute executes the Execution and returns the updated LegalHold.
func (ex *Execution) Execute() (*model.LegalHold, error) {
now := time.Now().Unix()

// Lock multiple executions using a cluster mutex
mutexKey := fmt.Sprintf("legal_hold_%s_execution", ex.LegalHold.ID)
mutex, err := cluster.NewMutex(ex.papi, mutexKey)
if err != nil {
return nil, fmt.Errorf("failed to create cluster mutex: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), executionGlobalTimeout*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), executionGlobalTimeout)
defer cancel()

if lockErr := mutex.LockWithContext(ctx); lockErr != nil {
Expand Down Expand Up @@ -113,7 +115,14 @@ func (ex *Execution) Execute() (*model.LegalHold, error) {

// Update the LegalHold with execution results
ex.LegalHold.LastExecutionEndedAt = ex.ExecutionEndTime

// Ensure that the LastExecutionEndedAt is not in the future, useful when running the job manually
if ex.ExecutionEndTime > now {
ex.LegalHold.LastExecutionEndedAt = now
}

ex.LegalHold.Status = model.LegalHoldStatusIdle

return &ex.LegalHold, nil
}

Expand Down Expand Up @@ -185,20 +194,16 @@ func (ex *Execution) ExportData() error {
break
}

// Update LastMessageAt if we have newer messages
for _, post := range posts {
if post.PostCreateAt > ex.LegalHold.LastMessageAt {
ex.LegalHold.LastMessageAt = post.PostCreateAt
}
}

ex.papi.LogDebug("Legal hold executor - ExportData", "channel_id", channelID, "post_count", len(posts))

err = ex.WritePostsBatchToFile(channelID, posts)
if err != nil {
return err
}

// Update LastMessageAt with the last CreatedAt post
ex.LegalHold.LastMessageAt = posts[len(posts)-1].PostCreateAt

// Extract the FileIDs to export
var fileIDs []string
for _, post := range posts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const LegalHoldRow = (props: LegalHoldRowProps) => {
props.releaseLegalHold(lh);
};

const downloadUrl = `/plugins/com.mattermost.plugin-legal-hold/api/v1/legalholds/${lh.id}/download`;
const downloadUrl = Client.downloadUrl(lh.id);

return (
<React.Fragment>
Expand All @@ -56,7 +56,7 @@ const LegalHoldRow = (props: LegalHoldRowProps) => {
<div data-testid={`start-date-${lh.id}`}>{startsAt}</div>
<div data-testid={`end-date-${lh.id}`}>{endsAt}</div>
<div data-testid={`users-${lh.id}`}>{props.users.length} {'users'}</div>
<div
<div
data-testid={`last-run-${lh.id}`}
onClick={() => {
const newCount = resetClickCount + 1;
Expand Down

0 comments on commit cfadfd6

Please sign in to comment.