public static void SendCommand(string node, CommandInfo command) { Task.Factory.StartNew(() => { using (var zk = TaskNode.GetShortSessionZk(Timeout)) { zk.Create(GloabalConfig.CommandsRoot + "/" + node, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(command)), Ids.OPEN_ACL_UNSAFE, CreateMode.EphemeralSequential); Thread.Sleep(TimeSpan.FromSeconds(Timeout)); } }); Thread.Sleep(200); }
public static void SubmitJob(string name, string zipPath, string corn, CommandInfo executeCommand) { if (!File.Exists(zipPath)) { throw new FileNotFoundException(zipPath); } using (var zk = TaskNode.GetShortSessionZk(Timeout)) { for (int i = 0; (i < 50) && zk.Exists(GloabalConfig.SchedulerLock, false) != null; ++i) { Thread.Sleep(1000); } //锁住 zk.Create(GloabalConfig.SchedulerLock, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral); List<JobInfo> jobInfos = JsonConvert.DeserializeObject<List<JobInfo>>(Encoding.UTF8.GetString(zk.GetData(GloabalConfig.Scheduler, false, null))); if (!jobInfos.Exists(j => j.Name == name)) { jobInfos.Add(new JobInfo { Name = name, Corn = corn, ExecuteCommand = executeCommand }); zk.SetData(GloabalConfig.Scheduler, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jobInfos)), -1); string appstorePath = GloabalConfig.AppDataRoot + "/" + name; if (zk.Exists(appstorePath, false) == null) { zk.Create(appstorePath, Encoding.UTF8.GetBytes("jobapp"), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent); } zk.Create(appstorePath + "/zip", File.ReadAllBytes(zipPath), Ids.OPEN_ACL_UNSAFE, CreateMode.PersistentSequential); } else { throw new ExistsSameJobException(); } } }
internal static void Run(CommandInfo comandInfo) { Running.Add(comandInfo); }