Skip to content

Commit 1d096e5

Browse files
divyagandhisethipragnagopa
authored andcommitted
Fix background sync triggers for Kubernetes scenarios (#7373)
1 parent 55faf4e commit 1d096e5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ public async Task<SyncTriggersResult> TrySyncTriggersAsync(bool isBackgroundSync
106106
await _syncSemaphore.WaitAsync();
107107

108108
var hashBlobClient = await GetHashBlobAsync();
109-
if (isBackgroundSync && hashBlobClient == null)
109+
if (isBackgroundSync && hashBlobClient == null && !_environment.IsKubernetesManagedHosting())
110110
{
111111
// short circuit before doing any work in background sync
112112
// cases where we need to check/update hash but don't have
113-
// storage access
113+
// storage access in non-Kubernetes environments.
114114
return result;
115115
}
116116

@@ -127,7 +127,7 @@ public async Task<SyncTriggersResult> TrySyncTriggersAsync(bool isBackgroundSync
127127

128128
bool shouldSyncTriggers = true;
129129
string newHash = null;
130-
if (isBackgroundSync)
130+
if (isBackgroundSync && !_environment.IsKubernetesManagedHosting())
131131
{
132132
newHash = await CheckHashAsync(hashBlobClient, payload.Content);
133133
shouldSyncTriggers = newHash != null;

src/WebJobs.Script/Host/Kubernetes/KubernetesClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ internal async Task<KubernetesLockHandle> TryAcquireLock (string lockId, string
6666
{
6767
lockHandle.LockId = lockId;
6868
lockHandle.Owner = ownerId;
69+
lockHandle.LockPeriod = lockPeriod.TotalSeconds.ToString();
6970
}
7071
return lockHandle;
7172
}

test/WebJobs.Script.Tests.Integration/KubernetesDistributedLockManagerTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ public async Task AcquireLockRequest_ReturnsCorrectLockHandle(HttpStatusCode sta
4646

4747
if (status == HttpStatusCode.OK)
4848
{
49-
Assert.Equal(expectedLockId, lockHandle.LockId);
50-
Assert.Equal(expectedOwnerId, ((KubernetesLockHandle)lockHandle).Owner);
49+
Assert.IsType<KubernetesLockHandle> (lockHandle);
50+
51+
var kubernetesLockHandleResult = (KubernetesLockHandle)lockHandle;
52+
Assert.Equal(expectedLockId, kubernetesLockHandleResult.LockId);
53+
Assert.Equal(expectedOwnerId, kubernetesLockHandleResult.Owner);
54+
Assert.Equal("5", kubernetesLockHandleResult.LockPeriod);
5155
}
5256
else
5357
{

0 commit comments

Comments
 (0)