public void SimplePush_Ok() { var pool = JobsPool.Get(); pool.SimplePush(Task.Run(() => {})); pool.SimplePush(Task.Run(() => {})); Assert.AreEqual(2, JobsPool.PoolSize()); pool.WaitAll(); pool.CleanUp(); }
public void CleanUp_Ok() { var pool = JobsPool.Get(); pool.SimplePush(Task.Run(() => {})); pool.SimplePush(Task.Run(() => {})); Assert.True(JobsPool.PoolSize() == 2); pool.WaitAll(); pool.CleanUp(); Assert.Zero(JobsPool.PoolSize()); }
public RegisterBonus() { Post("/api/v1/schedule/user/register_bonus/start", _ => { var task = Task.Run(() => { int tokenBonus = Convert.ToInt32( AppConfig.GetConfiguration("user:registration:token_bonus") ); if (tokenBonus <= 0) { return; } int pageIndex = 1; var users = DL.Model.User.User.Paginate(pageIndex, 100); while (users.Length > 0) { foreach (var user in users) { try { if ( !user.EmailConfirmed() || FundingTransactionRepository.Get(user).Length > 0 ) { continue; } var balance = UserBalanceRepository.FindOrCreate(user, CurrencyType.GitComToken); balance.UpdateBalance(balance.balance + tokenBonus); FundingTransactionRepository.Create( user, user.id, EntityType.UserBalance, 2M, CurrencyType.GitComToken, "Registration bonus" ); } catch (Exception e) { SentrySdk.CaptureException(e); } } ++pageIndex; users = DL.Model.User.User.Paginate(pageIndex, 100); } }); JobsPool.Get().Push(task); return(HttpResponse.Data(new JObject())); }); }
public void RegisterBonus_Ok() { var user = UserFaker.Create(); var browser = new Browser(new DefaultNancyBootstrapper()); var result = browser .Post("/api/v1/schedule/user/register_bonus/start", with => { with.HttpRequest(); with.Query("schedule_token", AppConfig.GetConfiguration("auth:schedule:token")); }).Result; Assert.Zero(FundingTransactionRepository.Get(user).Length); JobsPool.Get().WaitAll(); Assert.True(FundingTransactionRepository.Get(user).Length == 1); var balance = UserBalanceRepository.Find(user, CurrencyType.GitComToken); var tokenBonus = System.Convert.ToInt32(AppConfig.GetConfiguration("user:registration:token_bonus")); Assert.AreEqual(tokenBonus, balance.balance); }
public SyncIssues() { Post("/api/v1/schedule/issues/sync/start", _ => { var task = Task.Run(async() => { var githubClient = GitHubApi.Client(); var projects = DL.Model.Project.Project.GetRandom(50); foreach (var project in projects) { var board = project.Boards().First(x => x.name == "Development"); if (board == null) { continue; } var todoColumn = board.Columns().First(c => c.name == "TODO"); if (todoColumn == null) { continue; } try { var originId = project.Repository().origin_id; var issues = githubClient.Issue.GetAllForRepository( Convert.ToInt64(originId) , new ApiOptions() { PageSize = 100 } ).Result; foreach (var issue in issues) { try { var existingCard = Card.FindBy("origin_id", issue.Id.ToString()); if (existingCard != null) { continue; } var card = CardRepository.CreateAndGet( issue.Title, issue.Body ?? "", 1, todoColumn, null ); card.UpdateCol("origin_id", issue.Id.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } } } catch (AggregateException e) { if (e.Message.Contains("API rate limit")) { Console.WriteLine("waiting"); await Task.Delay(GitHubApi.TimeUntilReset() * 1000); } else { SentrySdk.CaptureException(e); } } catch (Exception e) { Console.WriteLine(e.Message); SentrySdk.CaptureException(e); } } Console.WriteLine("Finished!"); }); JobsPool.Get().Push(task); return(HttpResponse.Data(new JObject())); }); }
public void BeforeEachTest() { JobsPool.Get().CleanUp(); DbCleaner.TruncateAll(); }
public SyncReleases() { Post("/api/v1/schedule/project/sync_releases/start", _ => { var task = Task.Run(() => { var githubClient = new GitHubClient(new ProductHeaderValue("GitCom")); var githubToken = AppConfig.GetConfiguration("auth:external:github:token"); if (githubToken != null) { githubClient.Credentials = new Credentials(githubToken); } var repos = Repo.GetRandom(50); foreach (var repo in repos) { try { if (repo.service_type != RepoServiceType.GitHub) { continue; } var splitUrl = repo.repo_url.Split("/"); IEnumerable <Release> releases; try { releases = githubClient.Repository.Release.GetAll( splitUrl[3], splitUrl[4] ).Result.OrderBy(x => x.Id); } catch (Exception e) { continue; // ignored } foreach (var release in releases) { if (release.Body.Length < 100) { continue; } var existingPost = ProjectPost.FindBy("origin_id", release.Id.ToString()); if (existingPost != null) { continue; } var post = ProjectPost.Create( repo.Project(), $"Released {release.Name}", release.Body ); post.UpdateCol("origin_id", release.Id.ToString()); post.UpdateCol( "created_at", release.PublishedAt.Value.ToUnixTimeSeconds().ToString() ); } } catch (Exception e) { SentrySdk.CaptureException(e); } } }); JobsPool.Get().Push(task); return(HttpResponse.Data(new JObject())); }); }