private void StopJob() { JobWorker.Tell(new StopJob(Job, Stats.DeepClone(), Self)); Stats = Stats.Reset(); Become(ReadyToStart); }
private void ProcessingItems() { //Received word from the WorkerTracker that we need to process items Receive <ProcessItems>(process => { Stats = Stats.WithItemsDiscovered(process.Items.Count); JobWorker.Tell(Stats.DeepClone(), Self); foreach (var item in process.Items) { //hand the work off to the weightedshare workers ItemWorkerRouter.Tell(new ItemWorker.ProcessItemResult(item.Copy()), Self); } }); Receive <WorkerTracker.AllItemsCompleted>(ic => { _logger.Info("{0} Items processed.", ic.Items.Count); StopJob(); }); Receive <WorkerTracker.CompletedItem>(completed => { Stats = Stats.WithItemCompleted(); WorkerTracker.Tell(completed, Self); JobWorker.Tell(Stats.DeepClone(), Self); }); ReceiveAny(task => { _logger.Error(" [x] Oh Snap! WorkerCoordinator.ProcessingWeightedShare.ReceiveAny: \r\n{0}", task); }); }
public WorkerCoordinator(Job job, IActorRef jobWorker, IActorRef workerTracker) { Job = job; WorkerTracker = workerTracker; JobWorker = jobWorker; Stats = new JobStats(Job); Become(ReadyToStart); }
public JobWorker(Job job, IActorRef jobTrackingMaster) { _logger = Context.GetLogger(); Job = job; RunningStatus = new JobStatusUpdate(Job); TotalStats = new JobStats(Job); JobTrackingMaster = jobTrackingMaster; // Make the JobTrackingMaster a default subscriber so that it receives all updates. Subscribers.Add(JobTrackingMaster); BecomeReady(); }
private void ReadyToStart() { Receive <GetJobData>(ic => { Stats = new JobStats(Job); JobWorker.Tell(Stats.DeepClone(), Self); JobWorker.Tell(JobStatus.GetJobData, Self); Become(GetItemsToProcess); GetItemDataRef.Tell(new GetJobData(Job.JobInfo), Self); }); ReceiveAny(task => { _logger.Error(" [x] Oh Snap! WorkerCoordinator.ReadyToStart.ReceiveAny: \r\n{0}", task); }); }
public async Task <OperationResult> Update(JobStatsInputModel viewModel) { JobStats Entity = await jobsStatsRepository.GetByIdAsync(viewModel.Id); if (Entity is null) { Entity = new JobStats(); Entity.Update(viewModel); await jobsStatsRepository.AddAsync(Entity); } else { Entity.Update(viewModel); jobsStatsRepository.Update(Entity); } var result = await jobsStatsRepository.SaveChangesAsync(); return(result); }
public JobStats StatsJob(uint jobId) { var command = new Command { RequestLine = string.Format("stats-job {0}", jobId), ExpectData = line => Regex.IsMatch(line, "^OK \\d+$") }; BeginCommand(command); command.Wait(); if ("NOT_FOUND".Equals(command.ResponseLine, StringComparison.OrdinalIgnoreCase)) { return(null); } try { return(JobStats.Parse(LoadYaml(command.ResponseData))); } catch (Exception) { throw new BeanstalkdException(BeanstalkdExceptionCode.UnexpectedResponse); } }
public async void Start() { Plugin.log?.Debug("BeatSync Start()"); IsRunning = true; SetupComponents(); if (playlistManager != null) { var recentPlaylist = Plugin.config.RecentPlaylistDays > 0 ? playlistManager.GetOrAddPlaylist(BuiltInPlaylist.BeatSyncRecent) : null; if (recentPlaylist != null && Plugin.config.RecentPlaylistDays > 0) { var minDate = DateTime.Now - new TimeSpan(Plugin.config.RecentPlaylistDays, 0, 0, 0); int removedCount = recentPlaylist.RemoveAll(s => s.DateAdded < minDate); if (removedCount > 0) { Plugin.log?.Info($"Removed {removedCount} old songs from the RecentPlaylist."); recentPlaylist.RaisePlaylistChanged(); try { playlistManager.StorePlaylist(recentPlaylist); } catch (Exception ex) { Plugin.log?.Warn($"Unable to write {recentPlaylist.Filename}: {ex.Message}"); Plugin.log?.Debug(ex); } } else { Plugin.log?.Info("Didn't remove any songs from RecentPlaylist."); } } } var syncInterval = new TimeSpan(Plugin.modConfig.TimeBetweenSyncs.Hours, Plugin.modConfig.TimeBetweenSyncs.Minutes, 0); var nowTime = DateTime.Now; if (Plugin.config.LastRun + syncInterval <= nowTime) { if (Plugin.config.LastRun != DateTime.MinValue) { Plugin.log?.Info($"BeatSync ran {TimeSpanToString(nowTime - Plugin.config.LastRun)} ago"); } if (songHasher != null) { await songHasher.InitializeAsync().ConfigureAwait(false); Plugin.log?.Info($"Hashed {songHasher.HashDictionary.Count} songs in {CustomLevelsDirectory}."); } else { Plugin.log?.Error($"SongHasher was null."); } // Start downloader IJobBuilder jobBuilder = CreateJobBuilder(Plugin.config); SongDownloader songDownloader = new SongDownloader(); JobManager JobManager = new JobManager(Plugin.config.MaxConcurrentDownloads); JobManager.Start(CancelAllToken); Stopwatch sw = new Stopwatch(); sw.Start(); if (jobBuilder.SongTargets.Count() == 0) { Plugin.log?.Error("jobBuilder has no SongTargets."); } JobStats[] sourceStats = await songDownloader.RunAsync(Plugin.config, jobBuilder, JobManager).ConfigureAwait(false); // TODO: CancellationToken JobStats beatSyncStats = sourceStats.Aggregate((a, b) => a + b); await JobManager.CompleteAsync(); int recentPlaylistDays = Plugin.config.RecentPlaylistDays; DateTime cutoff = DateTime.Now - new TimeSpan(recentPlaylistDays, 0, 0, 0); foreach (SongTarget target in jobBuilder.SongTargets) { if (target is ITargetWithPlaylists targetWithPlaylists) { PlaylistManager?targetPlaylistManager = targetWithPlaylists.PlaylistManager; if (recentPlaylistDays > 0) { BeatSaberPlaylistsLib.Types.IPlaylist?recent = targetPlaylistManager?.GetOrAddPlaylist(BuiltInPlaylist.BeatSyncRecent); if (recent != null && recent.Count > 0) { int songsRemoved = recent.RemoveAll(s => s.DateAdded < cutoff); if (songsRemoved > 0) { recent.RaisePlaylistChanged(); } } } try { targetPlaylistManager?.StoreAllPlaylists(); } catch (AggregateException ex) { Plugin.log?.Error($"Error storing playlists: {ex.Message}"); foreach (var e in ex.InnerExceptions) { Plugin.log?.Debug(e); } } catch (Exception ex) { Plugin.log?.Error($"Error storing playlists: {ex.Message}"); Plugin.log?.Debug(ex); } } if (target is ITargetWithHistory targetWithHistory) { try { targetWithHistory.HistoryManager?.WriteToFile(); } catch (Exception ex) { Plugin.log?.Info($"Unable to save history at '{targetWithHistory.HistoryManager?.HistoryPath}': {ex.Message}"); } } } sw.Stop(); Plugin.log?.Info($"Finished after {sw.Elapsed.TotalSeconds}s: {beatSyncStats}"); Plugin.config.LastRun = DateTime.Now; Plugin.ConfigManager.SaveConfig(); SongCore.Loader loader = SongCore.Loader.Instance; SongCore.Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent; SongCore.Loader.SongsLoadedEvent += Loader_SongsLoadedEvent; if (!SongCore.Loader.AreSongsLoading) { SongCore.Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent; if (SongCore.Loader.AreSongsLoaded) { loader.RefreshSongs(); } } } else { Plugin.log?.Info($"BeatSync ran {TimeSpanToString(nowTime - Plugin.config.LastRun)} ago, skipping because TimeBetweenSyncs is {Plugin.modConfig.TimeBetweenSyncs}"); } }
static async Task Main(string[] args) { try { ConsoleLogWriter?consoleLogger = SetupLogging(); string version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "0.0.0.0"; Logger.log.Info($"Starting BeatSyncConsole v{version}"); await CheckVersion().ConfigureAwait(false); ConfigManager = new ConfigManager(ConfigDirectory); bool validConfig = await ConfigManager.InitializeConfigAsync().ConfigureAwait(false); if (consoleLogger != null) { consoleLogger.LogLevel = ConfigManager.Config?.ConsoleLogLevel ?? BeatSyncLib.Logging.LogLevel.Info; } Config?config = ConfigManager.Config; if (validConfig && config != null && config.BeatSyncConfig != null) { SongFeedReaders.WebUtils.Initialize(new WebUtilities.HttpClientWrapper.HttpClientWrapper()); SongFeedReaders.WebUtils.WebClient.SetUserAgent("BeatSyncConsole/" + version); JobManager manager = new JobManager(config.BeatSyncConfig.MaxConcurrentDownloads); manager.Start(CancellationToken.None); IJobBuilder jobBuilder = await CreateJobBuilderAsync(config).ConfigureAwait(false); SongDownloader songDownloader = new SongDownloader(); Stopwatch sw = new Stopwatch(); sw.Start(); JobStats[] sourceStats = await songDownloader.RunAsync(config.BeatSyncConfig, jobBuilder, manager).ConfigureAwait(false); JobStats beatSyncStats = sourceStats.Aggregate((a, b) => a + b); await manager.CompleteAsync().ConfigureAwait(false); int recentPlaylistDays = config.BeatSyncConfig.RecentPlaylistDays; DateTime cutoff = DateTime.Now - new TimeSpan(recentPlaylistDays, 0, 0, 0); foreach (SongTarget?target in jobBuilder.SongTargets) { if (target is ITargetWithPlaylists targetWithPlaylists) { PlaylistManager?targetPlaylistManager = targetWithPlaylists.PlaylistManager; if (recentPlaylistDays > 0) { IPlaylist?recent = targetPlaylistManager?.GetOrAddPlaylist(BuiltInPlaylist.BeatSyncRecent); if (recent != null && recent.Count > 0) { int songsRemoved = recent.RemoveAll(s => s.DateAdded < cutoff); if (songsRemoved > 0) { recent.RaisePlaylistChanged(); } } } try { targetPlaylistManager?.StoreAllPlaylists(); } catch (AggregateException ex) { Logger.log.Error($"Error storing playlists: {ex.Message}"); foreach (var e in ex.InnerExceptions) { Logger.log.Debug(e); } } catch (Exception ex) { Logger.log.Error($"Error storing playlists: {ex.Message}"); Logger.log.Debug(ex); } } if (target is ITargetWithHistory targetWithHistory) { try { targetWithHistory.HistoryManager?.WriteToFile(); } catch (Exception ex) { Logger.log.Info($"Unable to save history at '{targetWithHistory.HistoryManager?.HistoryPath}': {ex.Message}"); } } } sw.Stop(); Logger.log.Info($"Finished after {sw.Elapsed.TotalSeconds}s: {beatSyncStats}"); config.BeatSyncConfig.LastRun = DateTime.Now; } else { Logger.log.Info("BeatSyncConsole cannot run without a valid config, exiting."); } LogManager.Stop(); LogManager.Wait(); Console.WriteLine("Press Enter to continue..."); Console.Read(); } catch (Exception ex) { string message = $"Fatal Error in BeatSyncConsole: {ex.Message}\n{ex.StackTrace}"; if (LogManager.IsAlive && LogManager.HasWriters && Logger.log != null) { Logger.log.Error(message); } else { ConsoleColor previousColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(message); Console.ForegroundColor = previousColor; } LogManager.Stop(); LogManager.Wait(); Console.WriteLine("Press Enter to continue..."); Console.Read(); } finally { LogManager.Abort(); } }
public IActionResult Dashboard() { JArray servers = DataFactory.GetServers(directory); JArray OUMapping = DataFactory.GetOUMappingList(directory); JArray oumList = new JArray(); foreach (JObject ou in OUMapping) { JObject meta = (JObject)ou.GetValue("meta"); string sourceID = meta.GetValue("source").ToString(); string destID = meta.GetValue("destination").ToString(); string sourceName = ""; string destName = ""; foreach (JObject s in servers) { if (sourceID == s.GetValue("ID").ToString()) { sourceName = s.GetValue("name").ToString(); } if (destID == s.GetValue("ID").ToString()) { destName = s.GetValue("name").ToString(); } } JObject ouObj = new JObject(); ouObj.Add("sourceID", sourceID); ouObj.Add("sourceName", sourceName); ouObj.Add("destID", destID); ouObj.Add("destName", destName); oumList.Add(ouObj); } JArray jobs = DataFactory.GetJobs(directory); JobStats js = new JobStats(); foreach (JObject j in jobs) { JObject meta = (JObject)j.GetValue("meta"); int jobCount = ((JArray)j.GetValue("jobs")).Count(); string sourceDest = meta.GetValue("sourceName").ToString() + "/" + meta.GetValue("destinationName").ToString(); string level = meta.GetValue("levelName").ToString(); string periodType = ""; switch (meta.GetValue("periodType").ToString()) { case "1": periodType = "Daily"; break; case "2": periodType = "Monthly"; break; case "3": periodType = "Yearly"; break; default: break; } js.AddStat(sourceDest, jobCount, JobStats.StatType.SourceDestination); js.AddStat(level, jobCount, JobStats.StatType.Level); js.AddStat(periodType, jobCount, JobStats.StatType.Period); } JArray xfers = DataFactory.GetXfers(directory); ViewBag.servers = servers; ViewBag.oumList = oumList; ViewBag.serverCount = servers.Count(); ViewBag.oumCount = oumList.Count(); ViewBag.jobCount = jobs.Count(); ViewBag.xferCount = xfers.Count(); ViewBag.jobStats = js; return(View()); }
private void Ready() { // kick off the job Receive <IStartJob>(start => { _logger.Info("JobWorker.Ready.IStartJob"); // Need to reset tracking buckets. WorkerTracker.Tell(new WorkerTracker.ResetTrackerBuckets()); RunningStatus = new JobStatusUpdate(Job) { Status = JobStatus.Starting }; TotalStats = new JobStats(Job); RunningStatus.Stats = TotalStats; if (!Subscribers.Contains(start.Requestor)) { Subscribers.Add(start.Requestor); } PublishJobStatus(); Self.Tell(new JobCanStart(start.Job)); }); Receive <JobCanStart>(start => { RunningStatus.Status = JobStatus.Running; CoordinatorRouter.Tell(new WorkerCoordinator.GetJobData(start.Job.JobInfo)); Become(Started); Stash.UnstashAll(); }); Receive <JobCanStart>(start => { _logger.Warning("Can't start job yet. No routees."); }); Receive <CheckJobStatus>(start => { Sender.Tell(new ReceivedJobStatus(Job, RunningStatus), Self); }); Receive <ReceiveTimeout>(ic => { _logger.Error("JobWorker.Ready.ReceiveTimeout: \r\n{0}", ic); }); Receive <ISubscribeToJob>(subscribe => { Stash.Stash(); }); ReceiveAny(o => { _logger.Error("JobWorker.Ready.ReceiveAny and stashing: \r\n{0}", o); Stash.Stash(); }); }
public StopJob(Job job, JobStats jobStats, IActorRef requestor) { Requestor = requestor; Job = job; JobStats = jobStats; }