2017-12-04 1 views
0

약속을 예약하는 컨트롤러 메서드가 있습니다. 나는 약속을하기 전에 서비스에 로그인하기 위해 5 분 전에 SMS (twilio)를 통해 사용자에게 상기시키는 작업을 계획하고있다. 여기 Hang Fire에서 전화 걸기가 어려움

내 메서드 호출입니다 :

private SMSNotifier sms = new SMSNotifier(); 
BackgroundJob.Schedule(() => sms.SendPatientUpcomingApptNotificationTest(appointment), appointment.Start.AddMinutes(-5)); 

여기 내 클래스 :

public SMSNotifier() 
    { 
     var accountSid = ConfigurationManager.AppSettings["TwilioSid"]; 
     // Your Auth Token from twilio.com/console 
     var authToken = ConfigurationManager.AppSettings["TwilioToken"]; ; 

     TwilioClient.Init(accountSid, authToken); 
    } 


    public void SendPatientUpcomingApptNotificationTest(Appointment appt) 
    { 

      var message = MessageResource.Create(
     to: new PhoneNumber("+xxxxxxxxxx"), 
     from: new PhoneNumber("+xxxxxxxxxx"), 
     body: string.Format("Hello {0} {1}! You have an upcoming web based video appointment with xxxxxxxxxx. Please login to the website to be seen. Your appointment time is: {2} Thank you - xxxxxxxx", "xxxxxxx", "xxxxxxxx", appt.Start)); 

    } 
} 

나는이 오류가 계속 :

Server Error in '/' Application. 

Self referencing loop detected for property 'User' with type 'System.Data.Entity.DynamicProxies.AspNetUser_80E6332CC002F8FCF589159A68E74A0922BEE992586B9FE280D950E149CCC7EB'. Path 'Patient.ActiveSessions[0]'. 

하지만 난 그냥 이해가 안 돼요 왜. 어디서나 User 객체를 참조하지 않습니다.

나는 분명히 그 오류 봤 언급해야한다

:

  1. JSON.NET Error Self referencing loop detected for type

  2. Self referencing loop detected - Getting back data from WebApi to the browser

    가 ∞이의

아무도 제공하지 않는 y 진행. 나는 여전히 같은 오류가있다.

너희들은 어떻게 생각하니?

확실히 'SendPatientUpcomingApptNotificationTest'메소드를 예약하려는 방식과 관련이 있다고 생각합니다. Console.WriteLine을 할 수 있으며 작업을 대기열에 넣을 수 있습니다.

IE : 당신의 appointment 객체를 직렬화하려고 할 때이 오류로 실행중인 같은

BackgroundJob.Schedule(() => Console.WriteLine("TestSchedule"), appointment.Start.AddMinutes(-5)); 

가 작동

완벽

답변

1

소리가 난다.

배경 작업을 예약하면 Hangfire는 호출하려는 메소드 및 해당 인수에 대한 정보를 작업 저장소에 저장합니다. 메서드에 인수로 복잡한 객체를 전달하는 경우 전체 객체 그래프를 json으로 직렬화하려고 시도합니다.

recommended approach is to keep your job arguments small and simple. 예를 들어, 대신에 전체 예약의 작업에 appointmentId을 전달합니다

BackgroundJob.Schedule(() => sms.SendPatientUpcomingApptNotificationTest(appointmentId), ...); 

는 그런 다음 작업 내에서 실제 appointment를 검색합니다.

+0

감사합니다. Peter, 매우 도움이됩니다. 문제없이 대기업에 대기시킬 수있는 것 같습니다. 내 다른 질문은, SMSNotifier 클래스에 대한 생성자가 제대로 실행 되나요? 여전히 HangFire 콘솔에서 null 참조 오류가 발생합니다. 하지만 수동으로 SendPatientUpcomingApptNotificationTest 메서드를 실행할 때 제대로 작동합니다. 이상한가? – Waragi

+0

내 편이 맘에 안 든다. 피터, 고마워! – Waragi