protected override async Task RunImpl() { // When running for the first time, try to make sure we've refreshed videos from YouTube first and added some users before running int numberOfVideos = 1; if (IsFirstTimeRunning) { // Will throw if no videos are there yet, causing the job to be delayed and retried await _youTubeManager.GetUnusedVideos(10); // Check for users List <Guid> userIds = await _sampleDataRetriever.GetRandomSampleUserIds(10); if (userIds.Count == 0) { throw new InvalidOperationException("No sample users available yet. Waiting to run AddSampleYouTubeVideosJob."); } // Otherwise, we're good, add 10 sample videos the first time we run numberOfVideos = 10; } await _sampleDataService.AddSampleYouTubeVideos(new AddSampleYouTubeVideos { NumberOfVideos = numberOfVideos }).ConfigureAwait(false); }
public async Task <JsonNetResult> AddYouTubeVideos(AddYouTubeVideosViewModel model) { await _sampleDataService.AddSampleYouTubeVideos(new AddSampleYouTubeVideos { NumberOfVideos = model.NumberOfVideos }); return(JsonSuccess()); }