失败的天蓝色webjob(错误代码-2146232576)

时间:2015-06-15 10:59:43

标签: c# azure azure-webjobs

我的Azure WebJob始终以退出代码-2146232576失败。有谁知道退出代码与什么有关?

我正在尝试按计划运行它,我的源代码可以在这里找到:

https://github.com/luke-barnett/trakt-imdb250/tree/master/TrakIMDB250.Scraper

相关日志:

[06/15/2015 10:51:51 > 1e531f: SYS INFO] Status changed to Initializing
[06/15/2015 10:51:53 > 1e531f: SYS INFO] Run script 
  'TrakIMDB250.Scraper.exe' with script host - 'WindowsScriptHost'
[06/15/2015 10:51:53 > 1e531f: SYS INFO] Status changed to Running
[06/15/2015 10:51:53 > 1e531f: SYS INFO] Status changed to Failed
[06/15/2015 10:51:53 > 1e531f: SYS ERR ] Job failed due to exit code -2146232576

相关代码:

Program.cs的

using Microsoft.Azure.WebJobs;

namespace TrakIMDB250.Scraper
{
    class Program
    {
        static void Main(string[] args)
        {
            var config = new JobHostConfiguration();    
            var host = new JobHost(config);    
            host.Call(typeof(Functions).GetMethod("ScrapeIMDB250"));
        }
    }
}

functions.cs

using HtmlAgilityPack;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace TrakIMDB250.Scraper
{
    public class Functions
    {
        [NoAutomaticTrigger]
        public async static Task ScrapeIMDB250(TextWriter log)
        {
            await log.WriteLineAsync("[{0}] Starting scrapping of IMDB Top 250");    
            var html = new HtmlWeb().Load("http://www.imdb.com/chart/top");    
            var chartTable = html.DocumentNode.SelectSingleNode("//table[@class='chart']");    
            var movies = GetMovies(chartTable).OrderBy(movie => movie.Rank);    
            await log.WriteLineAsync("[{0}] Got movies");    
            var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["Storage"].ConnectionString);    
            var blobClient = storageAccount.CreateCloudBlobClient();    
            var container = blobClient.GetContainerReference("imdb-top250");    
            await container.CreateIfNotExistsAsync();    
            await container.SetPermissionsAsync(new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });    
            var jsonblob = container.GetBlockBlobReference("top250.json");    
            await jsonblob.UploadTextAsync(JsonConvert.SerializeObject(movies, Formatting.Indented));    
            await log.WriteLineAsync("[{0}] Written to blob storage");
        }

        static IEnumerable<Movie> GetMovies(HtmlNode chartTable)
        {
            foreach (var row in chartTable.SelectNodes(".//tr").Skip(1))
            {
                var title = row.SelectSingleNode("td[@class='titleColumn']");
                var rankSpan = title.SelectSingleNode("span[@name='ir']");
                var seenWidget = row.SelectSingleNode("td/span[@name='ur']/div");

                var name = title.SelectSingleNode("a").InnerText;
                var rank = int.Parse(new string(rankSpan.InnerText.Take(rankSpan.InnerText.Count() - 1).ToArray()));
                var rating = decimal.Parse(rankSpan.GetAttributeValue("data-value", "0"));
                var imdbid = seenWidget.GetAttributeValue("data-titleid", string.Empty);
                var releaseDate = DateTime.Parse(title.SelectSingleNode("span[@name='rd']").GetAttributeValue("data-value", string.Empty));

                yield return new Movie
                {
                    Name = name,
                    Rank = rank,
                    Rating = rating,
                    IMDBId = imdbid,
                    ReleaseDate = releaseDate
                };
            }
        }
    }
}

1 个答案:

答案 0 :(得分:10)

我的问题是我飞得太靠近太阳试图运行.NET 4.6。

将解决方案降级为4.5.2并且运行良好:)

注意:一旦4.6正式支持,这个解决方案就会变得无关紧要。

截至8/3/2018,此兼容性问题仍然存在问题。 .NET 4.7.2产生同样的错误,但降级到4.7.1会起作用。