c# - Exception when creating on demand loactor for Azure Media Services asset -


i'm using azure functions accessing azure media services. have http trigger me streaming link video file. when try create on demand streaming locator server return following error:

one or more errors occurred. microsoft.windowsazure.mediaservices.client: error occurred while processing request. locator's expirationdatetime cannot in past.

here part of code:

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 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 exception returned     }     ... } 

this seems inconsistent behaviour, work expected of time. once when happened tried put in log statements in azure function, , when saved changes function worked expected.

one thing realized writing timeskew variable not updated until save changes azure functions. means first time run timeskew example 5:00pm , after 5 hours timeskew still 5:00pm, meaning expirationtimethreshold , timeskew negate each other?

making timeskew local variable should fix problem?

i think answered own question. every time recompile (or more specifically, every time new instance starts running function), timeskew static variable initialized. subsequent requests same instance, timeskew value stays same, leads mentioned error.

solution: don't initialize static variable datetime.now related things, unless want track start time of first run on each instance (which don't).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -