2017-09-10 4 views
1

저는 Azure Media Services에 액세스하기 위해 Azure 함수를 사용하고 있습니다. 비디오 파일에 대한 스트리밍 링크를 얻을 수있는 HTTP 트리거가 있습니다.Azure Media Services 자산의 주문형 loactor를 만들 때 예외가 발생했습니다.

다음

One or more errors occurred. Microsoft.WindowsAzure.MediaServices.Client: An error occurred while processing this request. Locator's ExpirationDateTime cannot be in the past.

코드의 일부입니다 : 나는 서버가 때때로 다음과 같은 오류를 반환 디맨드 스트리밍에 로케이터를 만들려고 할 때 는

using System.Net; 
using Microsoft.WindowsAzure.MediaServices.Client; 
... 
public static readonly TimeSpan ExpirationTimeThreshold = TimeSpan.FromHours(5); 
public static readonly DateTime TimeSkew = DateTime.UtcNow.AddMinutes(-5); 
... 

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) 
{ 
    string assetId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "assetId", true) == 0).Value; 

    IAsset wantedAsset = _context.Assets.Where(a => a.Id.Equals(assetId)).FirstOrDefault(); 

    if (wantedAsset == null) 
    { 
     return req.CreateResponse(HttpStatusCode.BadRequest, 
     "No asset matches the Id"); 

    } 

    originLocator = wantedAsset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin).FirstOrDefault(); 

    if (originLocator == null) 
    { 
     IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy", 
     ExpirationTimeThreshold, 
     AccessPermissions.Read); 

     originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, wantedAsset, 
     policy, 
     TimeSkew); //This is where the exception is returned 
    } 
    ... 
} 

이 그것으로, 매우 모순 된 것 같다 대부분 예상대로 작동합니다. 이 문제가 발생하면 Azure 함수에 로그 문을 넣으려고했는데 변경 내용을 저장하면 함수가 예상대로 작동했습니다.

이 글을 쓰면서 깨달은 사실 중 하나는 Azure 함수에 변경 사항을 저장할 때까지 TimeSkew 변수가 업데이트되지 않는다는 것입니다. 즉, 이것은 처음에 오후 8 시부 터 오후 5 시까 지 TimeSkew과 같이 실행되며, TimeSkew은 오후 5 시가됩니다. 즉, ExpirationTimeThresholdTimeSkew은 서로를 무효로합니다.

TimeSkew 로컬 변수를 작성하면 문제가 해결됩니까?

답변

1

나는 이미 자신의 질문에 대답했다고 생각합니다. 다시 컴파일 할 때마다 (또는 더 구체적으로 새 인스턴스가 함수를 시작할 때마다) TimeSkew 정적 변수가 초기화됩니다. 동일한 인스턴스에 대한 모든 후속 요청의 경우 TimeSkew 값은 동일하게 유지되므로 언급 된 오류가 발생할 수 있습니다.

해결 방법 : 정적 변수를 DateTime.Now 관련 변수로 초기화하지 마십시오 (실제로는 그렇지 않은 각 인스턴스에서 첫 번째 실행의 시작 시간을 추적하지 않는 한).

+0

그런 식으로 보입니다. 테스트를 마쳤으므로 이제는 제대로 작동합니다. – simjes