-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add support for scheduled functions to Go client #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8d320db
c157834
0f0bfd2
1e3ea97
c8fc76b
f043261
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we pass the schedules to the deploy options. |
||
} | ||
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to pointers here is just so that it matches the
FunctionSchedules
type fromDeployFiles
without doing any conversion.