forked from projectkudu/kudu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support webjobs in secondary location site/jobs
- Loading branch information
1 parent
0d4fd5a
commit f2e2586
Showing
18 changed files
with
246 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Kudu.Contracts.Jobs; | ||
using Kudu.Contracts.Settings; | ||
using Kudu.Core.Tracing; | ||
|
||
namespace Kudu.Core.Jobs | ||
{ | ||
public class AggregrateContinuousJobsManager : AggregrateJobsManagerBase<ContinuousJob>, IContinuousJobsManager | ||
{ | ||
public AggregrateContinuousJobsManager(ITraceFactory traceFactory, IEnvironment environment, IDeploymentSettingsManager settings, IAnalytics analytics) | ||
: base(new ContinuousJobsManager(environment.JobsBinariesPath, traceFactory, environment, settings, analytics), | ||
excludedList => new ContinuousJobsManager(environment.SecondaryJobsBinariesPath, traceFactory, environment, settings, analytics, excludedList), | ||
settings) | ||
{ | ||
} | ||
|
||
public void DisableJob(string jobName) | ||
=> GetContinuousWriteJobManager(jobName).DisableJob(jobName); | ||
|
||
public void EnableJob(string jobName) | ||
=> GetContinuousWriteJobManager(jobName).EnableJob(jobName); | ||
|
||
public Task<HttpResponseMessage> HandleRequest(string jobName, string path, HttpRequestMessage request) | ||
=> PrimaryJobManager.HasJob(jobName) | ||
? (PrimaryJobManager as IContinuousJobsManager).HandleRequest(jobName, path, request) | ||
: (SecondaryJobManager as IContinuousJobsManager).HandleRequest(jobName, path, request); | ||
|
||
IContinuousJobsManager GetContinuousWriteJobManager(string jobName) => GetWriteJobManagerForJob(jobName) as IContinuousJobsManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Kudu.Contracts.Jobs; | ||
using Kudu.Contracts.Settings; | ||
|
||
namespace Kudu.Core.Jobs | ||
{ | ||
public abstract class AggregrateJobsManagerBase<TJob> where TJob : JobBase, new() | ||
{ | ||
protected JobsManagerBase<TJob> PrimaryJobManager { get; private set; } | ||
protected JobsManagerBase<TJob> SecondaryJobManager { get; private set; } | ||
private readonly IDeploymentSettingsManager _settings; | ||
|
||
protected AggregrateJobsManagerBase(JobsManagerBase<TJob> primaryManager, Func<IEnumerable<string>, JobsManagerBase<TJob>> secondaryManagerFactory, IDeploymentSettingsManager settings) | ||
{ | ||
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; | ||
} | ||
|
||
public void DeleteJob(string jobName) | ||
{ | ||
if (_settings.RunFromZip()) | ||
{ | ||
SecondaryJobManager.DeleteJob(jobName); | ||
} | ||
else | ||
{ | ||
// Make sure to delete the job from both managers if it exists. | ||
// Calling DeleteJob on a non-existing job is a no-op. | ||
PrimaryJobManager.DeleteJob(jobName); | ||
SecondaryJobManager.DeleteJob(jobName); | ||
} | ||
} | ||
|
||
public void CleanupDeletedJobs() | ||
{ | ||
PrimaryJobManager.CleanupDeletedJobs(); | ||
SecondaryJobManager.CleanupDeletedJobs(); | ||
} | ||
|
||
public TJob CreateOrReplaceJobFromFileStream(Stream scriptFileStream, string jobName, string scriptFileName) | ||
=> GetWriteJobManagerForJob(jobName).CreateOrReplaceJobFromFileStream(scriptFileStream, jobName, scriptFileName); | ||
|
||
public TJob CreateOrReplaceJobFromZipStream(Stream zipStream, string jobName) | ||
=> GetWriteJobManagerForJob(jobName).CreateOrReplaceJobFromZipStream(zipStream, jobName); | ||
|
||
public TJob GetJob(string jobName) | ||
=> PrimaryJobManager.HasJob(jobName) ? PrimaryJobManager.GetJob(jobName) : SecondaryJobManager.GetJob(jobName); | ||
|
||
public JobSettings GetJobSettings(string jobName) | ||
=> PrimaryJobManager.HasJob(jobName) ? PrimaryJobManager.GetJobSettings(jobName) : SecondaryJobManager.GetJobSettings(jobName); | ||
|
||
public bool HasJob(string jobName) | ||
=> PrimaryJobManager.HasJob(jobName) || SecondaryJobManager.HasJob(jobName); | ||
|
||
public IEnumerable<TJob> ListJobs(bool forceRefreshCache) | ||
=> PrimaryJobManager.ListJobs(forceRefreshCache).Concat(SecondaryJobManager.ListJobs(forceRefreshCache)); | ||
|
||
public void RegisterExtraEventHandlerForFileChange(Action<string> action) | ||
{ | ||
PrimaryJobManager.RegisterExtraEventHandlerForFileChange(action); | ||
SecondaryJobManager.RegisterExtraEventHandlerForFileChange(action); | ||
} | ||
|
||
public void SetJobSettings(string jobName, JobSettings jobSettings) | ||
=> GetWriteJobManagerForJob(jobName).SetJobSettings(jobName, jobSettings); | ||
|
||
// Always sync webjobs brought in by site extensions | ||
// into the writable location. | ||
public void SyncExternalJobs(string sourcePath, string sourceName) | ||
=> WritableJobManager.SyncExternalJobs(sourcePath, sourceName); | ||
|
||
// Always sync webjobs brought in by site extensions | ||
// into the writable location. | ||
public void CleanupExternalJobs(string sourceName) | ||
=> WritableJobManager.CleanupExternalJobs(sourceName); | ||
|
||
// Writable manager is secondary if run from zip, and primary otherwise. | ||
private JobsManagerBase<TJob> WritableJobManager => _settings.RunFromZip() | ||
? SecondaryJobManager | ||
: PrimaryJobManager; | ||
|
||
// This checks both run from zip, and Primary.HasJob() | ||
// The point is that if we are in run from zip, we always use the secondary. | ||
// Otherwise, we use the manager where the job exists. This can be either the primary or the secondary. | ||
protected JobsManagerBase<TJob> GetWriteJobManagerForJob(string jobName) | ||
{ | ||
if (_settings.RunFromZip()) | ||
{ | ||
return SecondaryJobManager; | ||
} | ||
else if (PrimaryJobManager.HasJob(jobName)) | ||
{ | ||
return PrimaryJobManager; | ||
} | ||
else if (SecondaryJobManager.HasJob(jobName)) | ||
{ | ||
return SecondaryJobManager; | ||
} | ||
else | ||
{ | ||
return PrimaryJobManager; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Kudu.Contracts.Jobs; | ||
using Kudu.Contracts.Settings; | ||
using Kudu.Core.Hooks; | ||
using Kudu.Core.Tracing; | ||
|
||
namespace Kudu.Core.Jobs | ||
{ | ||
public class AggregrateTriggeredJobsManager : AggregrateJobsManagerBase<TriggeredJob>, ITriggeredJobsManager | ||
{ | ||
public AggregrateTriggeredJobsManager(ITraceFactory traceFactory, IEnvironment environment, IDeploymentSettingsManager settings, IAnalytics analytics, IWebHooksManager hooksManager) | ||
: base(new TriggeredJobsManager(environment.JobsBinariesPath, traceFactory, environment, settings, analytics, hooksManager), | ||
excludedList => new TriggeredJobsManager(environment.SecondaryJobsBinariesPath, traceFactory, environment, settings, analytics, hooksManager, excludedList), | ||
settings) | ||
{ | ||
} | ||
|
||
public TriggeredJobHistory GetJobHistory(string jobName, string etag, out string currentETag) | ||
=> GetManagerForJob(jobName).GetJobHistory(jobName, etag, out currentETag); | ||
|
||
public TriggeredJobRun GetJobRun(string jobName, string runId) | ||
=> GetManagerForJob(jobName).GetJobRun(jobName, runId); | ||
|
||
public TriggeredJobRun GetLatestJobRun(string jobName) | ||
=> GetManagerForJob(jobName).GetLatestJobRun(jobName); | ||
|
||
public Uri InvokeTriggeredJob(string jobName, string arguments, string trigger) | ||
=> GetManagerForJob(jobName).InvokeTriggeredJob(jobName, arguments, trigger); | ||
|
||
private ITriggeredJobsManager GetManagerForJob(string jobName) | ||
=> PrimaryJobManager.HasJob(jobName) | ||
? PrimaryJobManager as ITriggeredJobsManager | ||
: SecondaryJobManager as ITriggeredJobsManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.