Skip to content

Commit fe0097e

Browse files
authored
fix: skip upserting disabled function (#2770)
* chore: refactor function enabled check * fix: skip upserting disabled function
1 parent a64e8d0 commit fe0097e

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

internal/functions/deploy/deploy.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
1818
// Load function config and project id
19-
var skippedFunctions []string
2019
if err := utils.LoadConfigFS(fsys); err != nil {
2120
return err
2221
} else if len(slugs) > 0 {
@@ -25,12 +24,9 @@ func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bo
2524
return err
2625
}
2726
}
28-
} else if slugs, skippedFunctions, err = GetFunctionSlugs(fsys); err != nil {
27+
} else if slugs, err = GetFunctionSlugs(fsys); err != nil {
2928
return err
3029
}
31-
if len(skippedFunctions) > 0 {
32-
fmt.Fprintf(utils.GetDebugLogger(), "Skipped deploying the following functions: %s\n", strings.Join(skippedFunctions, ", "))
33-
}
3430
// TODO: require all functions to be deployed from config for v2
3531
if len(slugs) == 0 {
3632
return errors.Errorf("No Functions specified or found in %s", utils.Bold(utils.FunctionsDir))
@@ -49,23 +45,19 @@ func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bo
4945
return nil
5046
}
5147

52-
func GetFunctionSlugs(fsys afero.Fs) (slugs []string, disabledSlugs []string, err error) {
48+
func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) {
5349
pattern := filepath.Join(utils.FunctionsDir, "*", "index.ts")
5450
paths, err := afero.Glob(fsys, pattern)
5551
if err != nil {
56-
return nil, nil, errors.Errorf("failed to glob function slugs: %w", err)
52+
return nil, errors.Errorf("failed to glob function slugs: %w", err)
5753
}
5854
for _, path := range paths {
5955
slug := filepath.Base(filepath.Dir(path))
6056
if utils.FuncSlugPattern.MatchString(slug) {
61-
if isFunctionEnabled(slug) {
62-
slugs = append(slugs, slug)
63-
} else {
64-
disabledSlugs = append(disabledSlugs, slug)
65-
}
57+
slugs = append(slugs, slug)
6658
}
6759
}
68-
return slugs, disabledSlugs, nil
60+
return slugs, nil
6961
}
7062

7163
func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool, fsys afero.Fs) (config.FunctionConfig, error) {
@@ -100,9 +92,3 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool,
10092
}
10193
return functionConfig, nil
10294
}
103-
104-
func isFunctionEnabled(slug string) bool {
105-
functionConfig := utils.Config.Functions[slug]
106-
// If the function config Enabled is not defined, or defined and set to true
107-
return functionConfig.Enabled == nil || *functionConfig.Enabled
108-
}

internal/functions/serve/serve.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,20 @@ func parseEnvFile(envFilePath string, fsys afero.Fs) ([]string, error) {
209209
}
210210

211211
func populatePerFunctionConfigs(cwd, importMapPath string, noVerifyJWT *bool, fsys afero.Fs) ([]string, string, error) {
212-
slugs, skippedFunctions, err := deploy.GetFunctionSlugs(fsys)
212+
slugs, err := deploy.GetFunctionSlugs(fsys)
213213
if err != nil {
214214
return nil, "", err
215215
}
216-
if len(skippedFunctions) > 0 {
217-
fmt.Fprintf(utils.GetDebugLogger(), "Skipped serving the following functions: %s\n", strings.Join(skippedFunctions, ", "))
218-
}
219216
functionsConfig, err := deploy.GetFunctionConfig(slugs, importMapPath, noVerifyJWT, fsys)
220217
if err != nil {
221218
return nil, "", err
222219
}
223220
binds := []string{}
224221
for slug, fc := range functionsConfig {
222+
if !fc.IsEnabled() {
223+
fmt.Fprintln(os.Stderr, "Skipped serving Function:", slug)
224+
continue
225+
}
225226
modules, err := deploy.GetBindMounts(cwd, utils.FunctionsDir, "", fc.Entrypoint, fc.ImportMap, fsys)
226227
if err != nil {
227228
return nil, "", err

pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ type (
450450
}
451451
)
452452

453+
func (f function) IsEnabled() bool {
454+
// If Enabled is not defined, or defined and set to true
455+
return f.Enabled == nil || *f.Enabled
456+
}
457+
453458
func (c *baseConfig) Clone() baseConfig {
454459
copy := *c
455460
copy.Storage.Buckets = maps.Clone(c.Storage.Buckets)

pkg/function/batch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func (s *EdgeRuntimeAPI) UpsertFunctions(ctx context.Context, functionConfig con
3535
exists[f.Slug] = struct{}{}
3636
}
3737
for slug, function := range functionConfig {
38+
if !function.IsEnabled() {
39+
fmt.Fprintln(os.Stderr, "Skipped deploying Function:", slug)
40+
continue
41+
}
3842
for _, keep := range filter {
3943
if !keep(slug) {
4044
continue

0 commit comments

Comments
 (0)