-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delayed Notifications #298
base: master
Are you sure you want to change the base?
Conversation
.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"))); | ||
|
||
// Add the processing server as IHostedService | ||
services.AddHangfireServer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это точно нужно?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у hangfire клиент - серверная архитектура, где сервер и клиент общаются с общей бд
сервер нужно добавить, чтобы он брал задачи из бд и выполнял их время от времени
using HwProj.Repositories; | ||
|
||
|
||
namespace HwProj.NotificationsService.API.Repositories; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace надо сделать block-scoped
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace HwProj.NotificationsService.API.Models | ||
{ | ||
public sealed class NotificationsContext : DbContext | ||
{ | ||
public DbSet<Notification> Notifications { get; set; } | ||
public DbSet<ScheduleWork> ScheduleWorks { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public DbSet<ScheduleWork> ScheduleWorks { get; set; } | |
public DbSet<ScheduleJob> ScheduleJobs { get; set; } |
@@ -2,7 +2,7 @@ | |||
|
|||
namespace HwProj.Repositories | |||
{ | |||
public interface IEntity<TKey> | |||
public interface IEntity<TKey> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно отформатировать
{ | ||
public class UpdateTaskEvent : Event | ||
{ | ||
public CourseDTO Course { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можем ли мы из курса взять только необходимые данные?
public string TaskTitle { get; set; } | ||
|
||
public long TaskId { get; set; } | ||
|
||
//закладываюсь, что дату публикации не будут менять после публикации | ||
public DateTime PreviousPublicationDate { get; set; } | ||
|
||
public DateTime PublicationDate { get; set; } | ||
|
||
public DateTime? Deadline { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возможно, мы хотим старую задачу и новую задачу, а не набор отдельных полей?
|
||
namespace HwProj.Models.NotificationsService | ||
{ | ||
public class ScheduleWork : IEntity<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class ScheduleWork : IEntity<string> | |
public class ScheduleJob : IEntity<string> |
|
||
public override async Task HandleAsync(DeleteTaskEvent @event) | ||
{ | ||
var id = ScheduleWorkIdBuilder.Build(@event, @event.TaskId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По эвенту удаления не должны создаваться ключи других эвентов, тем более, что отменяемых эвентов может быть несколько
{ | ||
_ when eventType == typeof(NewTaskEvent) || eventType == typeof(UpdateTaskEvent) || | ||
eventType == typeof(DeleteTaskEvent) | ||
=> "Task", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для дедлайнов и публикаций ключи должны отличаться
feat: new task delayed notification
feat: create ScheduleEventHandler + UpdateScheduleEventHandler abstract classes feat: Create ScheduleWorksRepository feat: Add schedule homework task
fix: schedule works not implement IRepository interfaces fix: change ScheduleWork primary key
76fd0e2
to
ac1eaa0
Compare
Transferring CourseDataFilter
var userId = context.HttpContext.User.Claims | ||
.FirstOrDefault(claim => claim.Type.ToString() == "_id") | ||
?.Value;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var userId = context.HttpContext.User.Claims | |
.FirstOrDefault(claim => claim.Type.ToString() == "_id") | |
?.Value;; | |
var userId = context.HttpContext.User.FindFirst("_id"); |
Homeworks, | ||
Tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Думаю, нам не нужно это изменение
var course = await _coursesServiceClient.GetCourseById(@event.Course.Id); | ||
if (course == null) return; | ||
|
||
var studentIds = course.CourseMates.Select(t => t.StudentId).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var studentIds = course.CourseMates.Select(t => t.StudentId).ToArray(); | |
var studentIds = course.AcceptedStudents.Select(t => t.StudentId).ToArray(); |
await EventHandlerExtensions<NewTaskEvent>.DeleteScheduleJobAsync(@event, @event.TaskId, | ||
_scheduleJobsRepository); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай будем удалять джобу только тогда, когда её создаем: вынесем этот код из AddNotificationsAsync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Также нужно удалять джобы просто из репозитория
var accountsData = await _authServiceClient.GetAccountsData(studentIds); | ||
|
||
var url = _configuration["Url"]; | ||
var isTaskPublished = @event.PreviousEvent.PublicationDate < DateTimeUtils.GetMoscowNow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если задача опубликована, мы можем использовать логику из NewHomeworkTaskEventHandler
var predicate = (ScheduleJob scheduleJob) => | ||
{ | ||
var id = ScheduleJobIdHelper.ParseId(scheduleJob.Id); | ||
return id.CategoryId == categoryId && id.Category.Equals(category); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этот код не транслируется в SQL. Нужно или делать фильтрацию по объектному ключу и его полям, или составлять список всех буквальных ключей, и искать записи в бд по ним
No description provided.