Skip to content

Commit 98917e7

Browse files
authored
Split up apple and windows profile management cron jobs (#23975)
for #22824 This PR splits up the `newMDMProfileManager` function into two functions `newAppleMDMProfileManager` and `newWindowsMDMProfileManager`, the latter containing the code to start the windows-specific profile management job. This allows scheduling and scaling the Apple and Windows profile management jobs separately. Tested locally by checking that the jobs were scheduled at startup, and then triggering the `mdm_apple_profile_manager` and `mdm_windows_profile_manager` schedules via the `/trigger` API; nothing blew up.
1 parent e7605d2 commit 98917e7

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

cmd/fleet/cron.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ func appleMDMDEPSyncerJob(
11821182
}
11831183
}
11841184

1185-
func newMDMProfileManager(
1185+
func newAppleMDMProfileManagerSchedule(
11861186
ctx context.Context,
11871187
instanceID string,
11881188
ds fleet.Datastore,
@@ -1207,6 +1207,29 @@ func newMDMProfileManager(
12071207
schedule.WithJob("manage_apple_declarations", func(ctx context.Context) error {
12081208
return service.ReconcileAppleDeclarations(ctx, ds, commander, logger)
12091209
}),
1210+
)
1211+
1212+
return s, nil
1213+
}
1214+
1215+
func newWindowsMDMProfileManagerSchedule(
1216+
ctx context.Context,
1217+
instanceID string,
1218+
ds fleet.Datastore,
1219+
logger kitlog.Logger,
1220+
) (*schedule.Schedule, error) {
1221+
const (
1222+
name = string(fleet.CronMDMWindowsProfileManager)
1223+
// Note: per a request from #g-product we are running this cron
1224+
// every 30 seconds, we should re-evaluate how we handle the
1225+
// cron interval as we scale to more hosts.
1226+
defaultInterval = 30 * time.Second
1227+
)
1228+
1229+
logger = kitlog.With(logger, "cron", name)
1230+
s := schedule.New(
1231+
ctx, name, instanceID, defaultInterval, ds, ds,
1232+
schedule.WithLogger(logger),
12101233
schedule.WithJob("manage_windows_profiles", func(ctx context.Context) error {
12111234
return service.ReconcileWindowsProfiles(ctx, ds, logger)
12121235
}),

cmd/fleet/cron_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@ import (
2323
kitlog "github.com/go-kit/log"
2424
)
2525

26-
func TestNewMDMProfileManagerWithoutConfig(t *testing.T) {
26+
func TestNewAppleMDMProfileManagerWithoutConfig(t *testing.T) {
2727
ctx := context.Background()
2828
mdmStorage := &mdmmock.MDMAppleStore{}
2929
ds := new(mock.Store)
3030
cmdr := apple_mdm.NewMDMAppleCommander(mdmStorage, nil)
3131
logger := kitlog.NewNopLogger()
3232

33-
sch, err := newMDMProfileManager(ctx, "foo", ds, cmdr, logger)
33+
sch, err := newAppleMDMProfileManagerSchedule(ctx, "foo", ds, cmdr, logger)
34+
require.NotNil(t, sch)
35+
require.NoError(t, err)
36+
}
37+
38+
func TestNewWindowsMDMProfileManagerWithoutConfig(t *testing.T) {
39+
ctx := context.Background()
40+
ds := new(mock.Store)
41+
logger := kitlog.NewNopLogger()
42+
43+
sch, err := newWindowsMDMProfileManagerSchedule(ctx, "foo", ds, logger)
3444
require.NotNil(t, sch)
3545
require.NoError(t, err)
3646
}

cmd/fleet/serve.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ the way that the Fleet server works.
924924
}
925925

926926
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
927-
return newMDMProfileManager(
927+
return newAppleMDMProfileManagerSchedule(
928928
ctx,
929929
instanceID,
930930
ds,
@@ -935,6 +935,17 @@ the way that the Fleet server works.
935935
initFatal(err, "failed to register mdm_apple_profile_manager schedule")
936936
}
937937

938+
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
939+
return newWindowsMDMProfileManagerSchedule(
940+
ctx,
941+
instanceID,
942+
ds,
943+
logger,
944+
)
945+
}); err != nil {
946+
initFatal(err, "failed to register mdm_windows_profile_manager schedule")
947+
}
948+
938949
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
939950
return newMDMAPNsPusher(
940951
ctx,

server/fleet/cron_schedules.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
CronWorkerIntegrations CronScheduleName = "integrations"
2222
CronActivitiesStreaming CronScheduleName = "activities_streaming"
2323
CronMDMAppleProfileManager CronScheduleName = "mdm_apple_profile_manager"
24+
CronMDMWindowsProfileManager CronScheduleName = "mdm_windows_profile_manager"
2425
CronAppleMDMIPhoneIPadRefetcher CronScheduleName = "apple_mdm_iphone_ipad_refetcher"
2526
CronAppleMDMAPNsPusher CronScheduleName = "apple_mdm_apns_pusher"
2627
CronCalendar CronScheduleName = "calendar"

0 commit comments

Comments
 (0)