private List<MailBox> GetMailboxesForProcessing(TasksConfig tasksConfig, int tasksLimit, bool active) { using (var db = GetDb()) { var whereLoginDelayExpiredString = string.Format("{0} < UTC_TIMESTAMP()", MailboxTable.Columns.date_login_delay_expires .Prefix(MAILBOX_ALIAS)); var query = GetSelectMailBoxFieldsQuery() .Where(MailboxTable.Columns.is_processed.Prefix(MAILBOX_ALIAS), false) .Where(whereLoginDelayExpiredString) .Where(MailboxTable.Columns.is_removed.Prefix(MAILBOX_ALIAS), false) .Where(MailboxTable.Columns.enabled.Prefix(MAILBOX_ALIAS), true) .OrderBy(MailboxTable.Columns.date_checked.Prefix(MAILBOX_ALIAS), true) .SetMaxResults(tasksLimit); if (tasksConfig.OnlyTeamlabTasks) { query .Where(MailboxTable.Columns.is_teamlab_mailbox, true); } if (tasksConfig.EnableSignalr) { query.Where(MailboxTable.Columns.user_online.Prefix(MAILBOX_ALIAS), active); } else { var whereUserCheckedString = string.Format("({0} IS NULL OR TIMESTAMPDIFF(SECOND, {0}, UTC_TIMESTAMP()) {1} {2})", MailboxTable.Columns.date_user_checked.Prefix(MAILBOX_ALIAS), active ? "<" : ">", tasksConfig.ActiveInterval.Seconds); query.Where(whereUserCheckedString); } if (tasksConfig.WorkOnUsersOnly.Any()) query.Where(Exp.In(MailboxTable.Columns.id_user, tasksConfig.WorkOnUsersOnly)); var listResults = db.ExecuteList(query); var seletedTasks = listResults.ConvertAll(ToMailBox).ToList(); seletedTasks.ForEach(m => m.Active = active); return seletedTasks; } }
public List<MailBox> GetMailboxesForProcessing(TasksConfig tasksConfig, int needTasks) { var inactiveCount = (int) Math.Floor(needTasks*tasksConfig.InactiveMailboxesRatio/100); var activeCount = needTasks - inactiveCount; var mailboxes = GetActiveMailboxesForProcessing(tasksConfig, activeCount); var difference = inactiveCount + activeCount - mailboxes.Count; if (difference != 0) mailboxes.AddRange(GetInactiveMailboxesForProcessing(tasksConfig, difference)); return mailboxes; }
private List<MailBox> GetInactiveMailboxesForProcessing(TasksConfig tasksConfig, int tasksLimit) { _log.Debug("GetInactiveMailboxForProcessing()"); var mailboxes = GetMailboxesForProcessing(tasksConfig, tasksLimit, false); _log.Debug("Found {0} inactive tasks", mailboxes.Count); return mailboxes; }
private MailBox GetInactiveMailboxForProcessing(TasksConfig tasks_config) { var mail = GetMailboxForProcessing(tasks_config, "(cast({0} as decimal) - " + MailboxTable.Columns.user_time_checked.Prefix(mail_mailbox_alias) + " ) > {1}"); return(mail); }