protected void RunJobInstance(JobBase job, IJobLogger logger, string runId) { string scriptFileName = Path.GetFileName(job.ScriptFilePath); string scriptFileExtension = Path.GetExtension(job.ScriptFilePath); logger.LogInformation("Run script '{0}' with script host - '{1}'".FormatCurrentCulture(scriptFileName, job.ScriptHost.GetType().Name)); string siteMode = Settings.GetWebSitePolicy(); _analytics.JobStarted(job.Name.Fuzz(), scriptFileExtension, job.JobType, siteMode); try { var exe = _externalCommandFactory.BuildCommandExecutable(job.ScriptHost.HostPath, WorkingDirectory, IdleTimeout, NullLogger.Instance); // Set environment variable to be able to identify all processes spawned for this job exe.EnvironmentVariables[GetJobEnvironmentKey()] = "true"; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRootPath] = WorkingDirectory; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsName] = job.Name; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsType] = job.JobType; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsDataPath] = JobDataPath; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRunId] = runId; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsExtraUrlPath] = JobsManagerBase.GetJobExtraInfoUrlFilePath(JobDataPath); UpdateStatus(logger, "Running"); int exitCode = exe.ExecuteReturnExitCode( TraceFactory.GetTracer(), logger.LogStandardOutput, logger.LogStandardError, job.ScriptHost.ArgumentsFormat, job.RunCommand); if (exitCode != 0) { logger.LogError("Job failed due to exit code " + exitCode); } else { UpdateStatus(logger, "Success"); } } catch (Exception ex) { if (ex is ThreadAbortException) { // We kill the process when refreshing the job logger.LogInformation("Job aborted"); UpdateStatus(logger, "Aborted"); return; } logger.LogError(ex.ToString()); } }
internal static bool JobDirectoryHasChanged( Dictionary <string, FileInfoBase> sourceDirectoryFileMap, Dictionary <string, FileInfoBase> workingDirectoryFileMap, Dictionary <string, FileInfoBase> cachedSourceDirectoryFileMap, IJobLogger logger) { // enumerate all source directory files, and compare against the files // in the working directory (i.e. the cached directory) FileInfoBase foundEntry = null; foreach (var entry in sourceDirectoryFileMap) { if (workingDirectoryFileMap.TryGetValue(entry.Key, out foundEntry)) { if (entry.Value.LastWriteTimeUtc != foundEntry.LastWriteTimeUtc) { // source file has changed since we last cached it, or a source // file has been modified in the working directory. logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' timestamp differs between source and working directories.", entry.Key)); return(true); } } else { // A file exists in source that doesn't exist in our working // directory. This is either because a file was actually added // to source, or a file that previously existed in source has been // deleted from the working directory. logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' exists in source directory but not in working directory.", entry.Key)); return(true); } } // if we've previously run this check in the current process, // look for any file deletions by ensuring all our previously // cached entries are still present foreach (var entry in cachedSourceDirectoryFileMap) { if (!sourceDirectoryFileMap.TryGetValue(entry.Key, out foundEntry)) { logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' has been deleted.", entry.Key)); return(true); } } return(false); }
protected void RunJobInstance(JobBase job, IJobLogger logger, string runId, string trigger, int port = -1) { string scriptFileName = Path.GetFileName(job.ScriptFilePath); string scriptFileFullPath = Path.Combine(WorkingDirectory, job.RunCommand); string workingDirectoryForScript = Path.GetDirectoryName(scriptFileFullPath); logger.LogInformation("Run script '{0}' with script host - '{1}'".FormatCurrentCulture(scriptFileName, job.ScriptHost.GetType().Name)); using (var jobStartedReporter = new JobStartedReporter(_analytics, job, trigger, Settings.GetWebSiteSku(), JobDataPath)) { try { var exe = _externalCommandFactory.BuildCommandExecutable(job.ScriptHost.HostPath, workingDirectoryForScript, IdleTimeout, NullLogger.Instance); _shutdownNotificationFilePath = RefreshShutdownNotificationFilePath(job.Name, job.JobType); // Set environment variable to be able to identify all processes spawned for this job exe.EnvironmentVariables[GetJobEnvironmentKey()] = "true"; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRootPath] = WorkingDirectory; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsName] = job.Name; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsType] = job.JobType; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsDataPath] = JobDataPath; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRunId] = runId; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsCommandArguments] = job.CommandArguments; if (port != -1) { exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsPort] = port.ToString(); } if (_shutdownNotificationFilePath != null) { exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsShutdownNotificationFile] = _shutdownNotificationFilePath; } UpdateStatus(logger, "Running"); int exitCode = exe.ExecuteReturnExitCode( TraceFactory.GetTracer(), logger.LogStandardOutput, logger.LogStandardError, job.ScriptHost.ArgumentsFormat, scriptFileName, job.CommandArguments != null ? " " + job.CommandArguments : String.Empty); if (exitCode != 0) { string errorMessage = "Job failed due to exit code " + exitCode; logger.LogError(errorMessage); jobStartedReporter.Error = errorMessage; } else { UpdateStatus(logger, "Success"); } } catch (ThreadAbortException) { // We kill the process when refreshing the job logger.LogInformation("WebJob process was aborted"); UpdateStatus(logger, "Stopped"); } catch (Exception ex) { logger.LogError(ex.ToString()); jobStartedReporter.Error = ex.Message; } } }
internal static bool JobDirectoryHasChanged( Dictionary<string, FileInfoBase> sourceDirectoryFileMap, Dictionary<string, FileInfoBase> workingDirectoryFileMap, Dictionary<string, FileInfoBase> cachedSourceDirectoryFileMap, IJobLogger logger) { // enumerate all source directory files, and compare against the files // in the working directory (i.e. the cached directory) FileInfoBase foundEntry = null; foreach (var entry in sourceDirectoryFileMap) { if (workingDirectoryFileMap.TryGetValue(entry.Key, out foundEntry)) { if (entry.Value.LastWriteTimeUtc != foundEntry.LastWriteTimeUtc) { // source file has changed since we last cached it, or a source // file has been modified in the working directory. logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' timestamp differs between source and working directories.", entry.Key)); return true; } } else { // A file exists in source that doesn't exist in our working // directory. This is either because a file was actually added // to source, or a file that previously existed in source has been // deleted from the working directory. logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' exists in source directory but not in working directory.", entry.Key)); return true; } } // if we've previously run this check in the current process, // look for any file deletions by ensuring all our previously // cached entries are still present foreach (var entry in cachedSourceDirectoryFileMap) { if (!sourceDirectoryFileMap.TryGetValue(entry.Key, out foundEntry)) { logger.LogInformation(string.Format("Job directory change detected: Job file '{0}' has been deleted.", entry.Key)); return true; } } return false; }
protected void RunJobInstance(JobBase job, IJobLogger logger, string runId) { string scriptFileName = Path.GetFileName(job.ScriptFilePath); string scriptFileFullPath = Path.Combine(WorkingDirectory, job.RunCommand); string workingDirectoryForScript = Path.GetDirectoryName(scriptFileFullPath); logger.LogInformation("Run script '{0}' with script host - '{1}'".FormatCurrentCulture(scriptFileName, job.ScriptHost.GetType().Name)); using (var jobStartedReporter = new JobStartedReporter(_analytics, job, Settings.GetWebSitePolicy(), JobDataPath)) { try { var exe = _externalCommandFactory.BuildCommandExecutable(job.ScriptHost.HostPath, workingDirectoryForScript, IdleTimeout, NullLogger.Instance); _shutdownNotificationFilePath = RefreshShutdownNotificationFilePath(job.Name, job.JobType); // Set environment variable to be able to identify all processes spawned for this job exe.EnvironmentVariables[GetJobEnvironmentKey()] = "true"; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRootPath] = WorkingDirectory; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsName] = job.Name; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsType] = job.JobType; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsDataPath] = JobDataPath; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRunId] = runId; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsShutdownNotificationFile] = _shutdownNotificationFilePath; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsCommandArguments] = job.CommandArguments; UpdateStatus(logger, "Running"); int exitCode = exe.ExecuteReturnExitCode( TraceFactory.GetTracer(), logger.LogStandardOutput, logger.LogStandardError, job.ScriptHost.ArgumentsFormat, scriptFileName, job.CommandArguments != null ? " " + job.CommandArguments : String.Empty); if (exitCode != 0) { string errorMessage = "Job failed due to exit code " + exitCode; logger.LogError(errorMessage); jobStartedReporter.Error = errorMessage; } else { UpdateStatus(logger, "Success"); } } catch (Exception ex) { if (ex is ThreadAbortException) { // We kill the process when refreshing the job logger.LogInformation("Job aborted"); UpdateStatus(logger, "Aborted"); return; } logger.LogError(ex.ToString()); jobStartedReporter.Error = ex.Message; } } }
private void ConnectionOnConnectionUnblocked(object sender, EventArgs e) { Logger.LogInformation("Connection unblocked"); }