-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
93 lines (76 loc) · 3.87 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using System.Timers;
using System.Configuration;
using System.IO;
using System.Diagnostics;
namespace Shift.WebJob
{
class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var host = new JobHost();
StartJob();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
[NoAutomaticTrigger]
public static void StartJob()
{
//Run Jobs
var pjob = new ShiftService();
pjob.Start();
}
}
public class ShiftService
{
private static JobServer jobServer; //only one server per WebJob
public ShiftService()
{
var config = new Shift.ServerConfig();
config.AssemblyFolder = ConfigurationManager.AppSettings["AssemblyFolder"];
//config.AssemblyListPath = ConfigurationManager.AppSettings["AssemblyListPath"];
//config.ProcessID = ConfigurationManager.AppSettings["ShiftPID"];
config.MaxRunnableJobs = Convert.ToInt32(ConfigurationManager.AppSettings["MaxRunnableJobs"]);
config.DBConnectionString = ConfigurationManager.ConnectionStrings["ShiftDBConnection"].ConnectionString;
config.DBAuthKey = ConfigurationManager.AppSettings["DocumentDBAuthKey"]; //only used when using DocumentDB connection and StorageMode=documentdb
config.Workers = Convert.ToInt32(ConfigurationManager.AppSettings["ShiftWorkers"]);
config.ServerTimerInterval = Convert.ToInt32(ConfigurationManager.AppSettings["TimerInterval"]); //optional: default every 5 sec for getting jobs ready to run and run them
config.ServerTimerInterval2 = Convert.ToInt32(ConfigurationManager.AppSettings["CleanUpTimerInterval"]); //optional: default every 10 sec for server CleanUp()
config.StorageMode = ConfigurationManager.AppSettings["StorageMode"];
var progressDBInterval = ConfigurationManager.AppSettings["ProgressDBInterval"];
if (!string.IsNullOrWhiteSpace(progressDBInterval))
config.ProgressDBInterval = TimeSpan.Parse(progressDBInterval); //Interval when progress is updated in main DB
var autoDeletePeriod = ConfigurationManager.AppSettings["AutoDeletePeriod"];
config.AutoDeletePeriod = string.IsNullOrWhiteSpace(autoDeletePeriod) ? null : (int?)Convert.ToInt32(autoDeletePeriod);
//config.AutoDeleteStatus = new List<JobStatus?> { JobStatus.Completed, JobStatus.Error }; //Auto delete only the jobs that had completed or with error.
config.ForceStopServer = Convert.ToBoolean(ConfigurationManager.AppSettings["ForceStopServer"]); //Set to true to allow windows service to shut down after a set delay in StopServerDelay
config.StopServerDelay = Convert.ToInt32(ConfigurationManager.AppSettings["StopServerDelay"]);
config.PollingOnce = Convert.ToBoolean(ConfigurationManager.AppSettings["PollingOnce"]);
//config.EncryptionKey = ConfigurationManager.AppSettings["ShiftEncryptionParametersKey"]; //optional
jobServer = new Shift.JobServer(config);
}
public async void Start()
{
try
{
await jobServer.RunServerAsync();
}
catch (Exception ex)
{
throw;
}
}
public async void Stop()
{
await jobServer.StopServerAsync(); //Attempt to cancel and set stop
}
}
}