0
votes

I have the following code in my azure webjob

 class Program
    {
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            try
            {
                Console.WriteLine(String.Format("Inicio webjob:  {0}", DateTime.Now.ToString()));

                JobHostConfiguration config = new JobHostConfiguration();
                config.Tracing.ConsoleLevel = TraceLevel.Verbose;
                config.UseTimers();
                JobHost host = new JobHost(config);
                host.RunAndBlock();

                Console.WriteLine(String.Format("Fin webjob:  {0}", DateTime.Now.ToString()));

            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Error webjob:  {0}", ex.Message));
                Console.WriteLine(String.Format("Error webjob:  {0}", ex.StackTrace));
                //throw ex;
            }

        }
    }




  public class Functions
    {

        public static void CronJob([TimerTrigger("0 */1 * * * *")] TimerInfo timer)
        {
            try
            {
                Console.WriteLine(String.Format("Inicio lectura mensajes : {0}", DateTime.Now.ToString()));
                string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                                       Configuracion.StorageAccountName, Configuracion.
                                       StorageAccountKey);
                string _guid = Guid.NewGuid().ToString();
                string eventProcessorHostName = _guid;
                EventProcessorHost eventProcessorHost = new EventProcessorHost(
                                                                eventProcessorHostName,
                                                                Configuracion.EventHubName,
                                                                EventHubConsumerGroup.DefaultGroupName,
                                                                Configuracion.EventHubConnectionString,
                                                                storageConnectionString);
                Console.WriteLine("Registering EventProcessor...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
                eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options).Wait();
                //Console.WriteLine("Receiving.Press enter key to stop worker.");
                //Console.ReadLine();
                eventProcessorHost.UnregisterEventProcessorAsync().Wait();
                Console.WriteLine(String.Format("Fin lectura mensajes : {0}", DateTime.Now.ToString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
    }

However I get this error when I publish it as a webjob on the webjob console

[09/16/2016 22:59:14 > 279d7d: SYS INFO] Status changed to Initializing [09/16/2016 22:59:15 > 279d7d: SYS INFO] Run script 'SE.Medidas.Receptor.exe' with script host - 'WindowsScriptHost' [09/16/2016 22:59:15 > 279d7d: SYS INFO] Status changed to Running [09/16/2016 22:59:16 > 279d7d: ERR ] [09/16/2016 22:59:16 > 279d7d: ERR ] Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. [09/16/2016 22:59:16 > 279d7d: ERR ] at SE.Medidas.Receptor.Program.Main(String[] args) [09/16/2016 22:59:16 > 279d7d: SYS INFO] Status changed to Failed

[09/16/2016 22:59:16 > 279d7d: SYS ERR ] Job failed due to exit code -532462766

As you can see in the Console, it does not even print OUT my first Console.Writeline: "Inicio webjob: "

1
Not a duplicate, this is very specific to webjobs, and it works locally, not on the cloud.Luis Valencia

1 Answers

0
votes

According to your description, I followed Get started with Event Hubs to create my Event Hub on my side. After deploying to Azure, I could get the following result via WebJobs dashboard in KUDU.

Based on the error you provided, we could find that 'SE.Medidas.Receptor.exe' couldn't be launched successfully. So I assumed that there be something wrong with your deployed WebJob. In order to locate this issue, please try to disabled the function CronJob and add a new function to Functions class like this:

//Function triggered by a timespan schedule every 5 sec.
public static void TimerJob([TimerTrigger("*/5 * * * * *")] TimerInfo timerInfo)
{
    Console.WriteLine("Timer job fired!");
}

Redeploy your WebJob project to Azure and find whether it could work as expected.

Additionally, WebJobs have bindings to EventHub. You could use EventHubClient for sending messages and use EventProcessorHost for listening on messages. For more details, you could refer to EventHub-support.