public void CleanupDeletedJobs() { var jobs = ListJobs(forceRefreshCache: true).Select(j => j.Name); var jobsDataPath = Path.Combine(_environment.JobsDataPath, _jobType); JobsManagerBase.CleanupDeletedJobs(jobs, jobsDataPath, _traceFactory.GetTracer()); }
protected AggregateJobsManagerBase(JobsManagerBase <TJob> primaryManager, Func <IEnumerable <string>, JobsManagerBase <TJob> > secondaryManagerFactory, IDeploymentSettingsManager settings, IEnvironment environment, ITraceFactory traceFactory, string jobType) { PrimaryJobManager = primaryManager; // pass the list of primary job names so the second manager can excluded them SecondaryJobManager = secondaryManagerFactory(PrimaryJobManager.ListJobs(forceRefreshCache: false).Select(j => j.Name)); _settings = settings; _environment = environment; _traceFactory = traceFactory; _jobType = jobType; }
private void Report(object state = null) { // Make sure this code is only called once. if (Interlocked.Exchange(ref _reported, 1) == 0) { string scriptFileExtension = Path.GetExtension(_job.ScriptFilePath); string jobType = _job.JobType; // Recheck whether the job is marked as "using sdk" here since the SDK will create the marker file // on the fly so it requires a "first run" first. bool isUsingSdk = JobsManagerBase.IsUsingSdk(_jobDataPath); if (isUsingSdk) { jobType += "/SDK"; } _analytics.JobStarted(_job.Name.Fuzz(), scriptFileExtension, jobType, _siteMode, Error); } }
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()); } }