Beispiel #1
0
 private static void SetJobTraceListener(JobBase job, bool consoleLogOnly, IDictionary <string, string> argsDictionary)
 {
     if (consoleLogOnly)
     {
         job.SetJobTraceListener(new JobTraceListener());
     }
     else
     {
         var connectionString = JobConfigurationManager.GetArgument(argsDictionary, JobArgumentNames.LogsAzureStorageConnectionString);
         job.SetJobTraceListener(new AzureBlobJobTraceListener(job.JobName, connectionString));
     }
 }
Beispiel #2
0
 private static void SetJobTraceListener(JobBase job, bool consoleLogOnly)
 {
     if (consoleLogOnly)
     {
         job.SetJobTraceListener(new JobTraceListener());
         Trace.TraceWarning("You have chosen not to log messages to Azure blob storage. Note that this is NOT recommended");
     }
     else
     {
         job.SetJobTraceListener(new AzureBlobJobTraceListener(job.JobName));
     }
 }
Beispiel #3
0
        /// <summary>
        /// This is a static method to run a job whose args are passed in
        /// By default,
        ///     a) The job will be run continuously in a while loop. Could be overridden using 'once' argument
        ///     b) The sleep duration between each run when running continuously is 5000 milliSeconds. Could be overridden using '-Sleep' argument
        /// </summary>
        /// <param name="job">Job to run</param>
        /// <param name="commandLineArgs">Args contains args to the job runner like (dbg, once and so on) and for the job itself</param>
        /// <returns></returns>
        public static async Task Run(JobBase job, string[] commandLineArgs)
        {
            if (commandLineArgs.Length > 0 && string.Equals(commandLineArgs[0], "-dbg", StringComparison.OrdinalIgnoreCase))
            {
                commandLineArgs = commandLineArgs.Skip(1).ToArray();
                Debugger.Launch();
            }

            bool consoleLogOnly = false;

            if (commandLineArgs.Length > 0 && string.Equals(commandLineArgs[0], "-ConsoleLogOnly", StringComparison.OrdinalIgnoreCase))
            {
                commandLineArgs = commandLineArgs.Skip(1).ToArray();
                consoleLogOnly  = true;
            }

            // Set the default trace listener, so if we get args parsing issues they will be printed. This will be overriden by the configured trace listener
            // after config is parsed.
            job.SetJobTraceListener(new JobTraceListener());

            try
            {
                Trace.TraceInformation("Started...");

                // Get the args passed in or provided as an env variable based on jobName as a dictionary of <string argName, string argValue>
                var jobArgsDictionary = JobConfigurationManager.GetJobArgsDictionary(commandLineArgs, job.JobName, (ISecretReaderFactory)ServiceContainer.GetService(typeof(ISecretReaderFactory)));

                // Set JobTraceListener. This will be done on every job run as well
                SetJobTraceListener(job, consoleLogOnly, jobArgsDictionary);

                var runContinuously = !JobConfigurationManager.TryGetBoolArgument(jobArgsDictionary, JobArgumentNames.Once);
                var sleepDuration   = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.Sleep); // sleep is in milliseconds
                if (!sleepDuration.HasValue)
                {
                    sleepDuration = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.Interval);
                    if (sleepDuration.HasValue)
                    {
                        sleepDuration = sleepDuration.Value * 1000; // interval is in seconds
                    }
                }

                // Setup the job for running
                JobSetup(job, consoleLogOnly, jobArgsDictionary, ref sleepDuration);

                // Run the job loop
                await JobLoop(job, runContinuously, sleepDuration.Value, consoleLogOnly, jobArgsDictionary);
            }
            catch (Exception ex)
            {
                ex.TraceException();
            }

            // Flush here. This is VERY IMPORTANT!
            // Exception messages from when the job faults are still in the queue and need to be flushed.
            // Also, if the job is only run once, this is what flushes the queue.
            job.JobTraceListener.Close();
        }
Beispiel #4
0
 private static void SetJobTraceListener(JobBase job, bool consoleLogOnly)
 {
     if(consoleLogOnly)
     {
         job.SetJobTraceListener(new JobTraceListener());
         Trace.TraceWarning("You have chosen not to log messages to Azure blob storage. Note that this is NOT recommended");
     }
     else
     {
         job.SetJobTraceListener(new AzureBlobJobTraceListener(job.JobName));
     }
 }