diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index b8c82064..e62f5755 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -91,7 +91,7 @@ type DeployOptions struct { files *deployFiles functions *deployFiles - functionSchedules []models.FunctionSchedule + functionSchedules []*models.FunctionSchedule } type uploadError struct { @@ -212,7 +212,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * options.files = files - functions, schedules, err := bundle(options.FunctionsDir, options.Observer) + functions, schedules, err := bundle(ctx, options.FunctionsDir, options.Observer) if err != nil { if options.Observer != nil { options.Observer.OnFailedWalk() @@ -238,10 +238,15 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * } } + if len(schedules) > 0 { + deployFiles.FunctionSchedules = schedules + } + l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ - "site_id": options.SiteID, - "deploy_files": len(options.files.Sums), + "site_id": options.SiteID, + "deploy_files": len(options.files.Sums), + "scheduled_functions": len(schedules), }).Debug("Starting to deploy files") authInfo := context.GetAuthInfo(ctx) @@ -580,7 +585,7 @@ func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs return files, err } -func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { if functionDir == "" { return nil, nil, nil } @@ -592,7 +597,7 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models if err == nil { defer manifestFile.Close() - return bundleFromManifest(manifestFile, observer) + return bundleFromManifest(ctx, manifestFile, observer) } functions := newDeployFiles() @@ -638,13 +643,16 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, []models return functions, nil, nil } -func bundleFromManifest(manifestFile *os.File, observer DeployObserver) (*deployFiles, []models.FunctionSchedule, error) { +func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { manifestBytes, err := ioutil.ReadAll(manifestFile) if err != nil { return nil, nil, err } + logger := context.GetLogger(ctx) + logger.Debug("Found functions manifest file") + var manifest functionsManifest err = json.Unmarshal(manifestBytes, &manifest) @@ -653,7 +661,7 @@ func bundleFromManifest(manifestFile *os.File, observer DeployObserver) (*deploy return nil, nil, fmt.Errorf("malformed functions manifest file: %w", err) } - schedules := make([]models.FunctionSchedule, 0, len(manifest.Functions)) + schedules := make([]*models.FunctionSchedule, 0, len(manifest.Functions)) functions := newDeployFiles() for _, function := range manifest.Functions { @@ -670,7 +678,7 @@ func bundleFromManifest(manifestFile *os.File, observer DeployObserver) (*deploy } if function.Schedule != "" { - schedules = append(schedules, models.FunctionSchedule{ + schedules = append(schedules, &models.FunctionSchedule{ Cron: function.Schedule, Name: function.Name, }) diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index 0b5f5f44..7f49d4cd 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -203,7 +203,7 @@ func TestUploadFiles_Cancelation(t *testing.T) { } func TestBundle(t *testing.T) { - functions, schedules, err := bundle("../internal/data", mockObserver{}) + functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err) assert.Equal(t, 3, len(functions.Files)) @@ -247,7 +247,7 @@ func TestBundleWithManifest(t *testing.T) { defer os.Remove(manifestPath) assert.Nil(t, err) - functions, schedules, err := bundle("../internal/data", mockObserver{}) + functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err)