Skip to content

Commit

Permalink
Fix sync triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed May 24, 2021
1 parent d92a89d commit 09a3278
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
9 changes: 1 addition & 8 deletions Kudu.Core/Functions/SyncTriggerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ public async Task<string> SyncTriggers(string functionTriggersPayload)

var scaleTriggers = scaleTriggersContent.Item1;
string appName = _environment.K8SEAppName;
string buildNumber = Guid.NewGuid().ToString();
var buildMetadata = new BuildMetadata()
{
AppName = appName,
BuildVersion = buildNumber,
AppSubPath = string.Empty
};

await Task.Run(() => K8SEDeploymentHelper.UpdateFunctionAppTriggers(appName, scaleTriggers, buildMetadata));
await Task.Run(() => K8SEDeploymentHelper.UpdateFunctionAppTriggers(appName, scaleTriggers, null));
}

return null;
Expand Down
31 changes: 14 additions & 17 deletions Kudu.Core/K8SE/K8SEDeploymentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static string GetAppKind(HttpContext context)
throw new InvalidOperationException("Couldn't recognize AppKind");
}

return appKind;
return appKind;
}

public static string GetAppNamespace(HttpContext context)
Expand Down Expand Up @@ -214,33 +214,30 @@ public static void UpdateContextWithAppSettings(HttpContext context)

private static string GetFunctionAppPatchJson(IEnumerable<ScaleTrigger> functionTriggers, BuildMetadata buildMetadata)
{
if (functionTriggers == null || !functionTriggers.Any())
if ((functionTriggers == null || !functionTriggers.Any()) && buildMetadata == null)
{
return null;
}

if (buildMetadata == null )
var patchAppJson = new PatchAppJson { PatchSpec = new PatchSpec { } };
if (functionTriggers?.Any() == true)
{
return null;
patchAppJson.PatchSpec.TriggerOptions = new TriggerOptions
{
Triggers = functionTriggers
};
}

var patchAppJson = new PatchAppJson
if (buildMetadata != null)
{
PatchSpec = new PatchSpec
patchAppJson.PatchSpec.Code = new CodeSpec
{
TriggerOptions = new TriggerOptions
{
Triggers = functionTriggers
},
Code = new CodeSpec
PackageRef = new PackageReference
{
PackageRef = new PackageReference
{
BuildMetadata = GetBuildMetadataStr(buildMetadata),
}
BuildMetadata = GetBuildMetadataStr(buildMetadata),
}
}
};
};
}

var str= System.Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(JsonConvert.SerializeObject(patchAppJson)));
Console.WriteLine("Test Str: " + str);
Expand Down

0 comments on commit 09a3278

Please sign in to comment.