protected virtual async Task ExecuteJobAsync(JobDefinition def) { var @lock = _lockFactory.CreateAsync(def.Name, TimeSpan.FromMinutes(1)).Result; var guid = Guid.NewGuid().ToString(); if (!await @lock.TryAcquireAsync()) { return; } var result = await _jobs.CreateResultAsync(def.Name, guid, DateTimeOffset.Now); try { await _aciService.CreateAsync(guid, def.Image, def.Private, def.OS, def.CPU, def.Memory, def.GetEnvVariables()); await WaitAndWriteLog(result); } catch (Exception ex) { await _jobs.WriteLogAsync(def.Name, result.RowKey, ex.ToString(), ResultStatus.Failed, DateTimeOffset.Now); } finally { await @lock.ReleaseLeaseAsync(); } }