mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #40054 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Updated logging infrastructure across background jobs and worker services to use standardized structured logging, improving consistency and log output formatting across the system. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"log/slog"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
type BatchScripts struct {
|
|
Datastore fleet.Datastore
|
|
Log *slog.Logger
|
|
}
|
|
|
|
func (b *BatchScripts) Name() string {
|
|
return fleet.BatchActivityScriptsJobName
|
|
}
|
|
|
|
func (b *BatchScripts) Run(ctx context.Context, jobArgs json.RawMessage) error {
|
|
var args fleet.BatchActivityScriptJobArgs
|
|
|
|
if err := json.Unmarshal(jobArgs, &args); err != nil {
|
|
return ctxerr.Wrap(ctx, err, "unmarshal json")
|
|
}
|
|
|
|
activity, err := b.Datastore.GetBatchActivity(ctx, args.ExecutionID)
|
|
if err != nil {
|
|
return ctxerr.Wrap(ctx, err, "could not find batch activity")
|
|
}
|
|
|
|
// The job was already started, close the job
|
|
if activity.Status != fleet.ScheduledBatchExecutionScheduled {
|
|
return nil
|
|
}
|
|
|
|
// The activity was canceled, close the job
|
|
if activity.Canceled {
|
|
return nil
|
|
}
|
|
|
|
if err := b.Datastore.RunScheduledBatchActivity(ctx, args.ExecutionID); err != nil {
|
|
return ctxerr.Wrap(ctx, err, "running scheduled batch script")
|
|
}
|
|
|
|
return nil
|
|
}
|