나는이 때 문에 두 개의 긴 명령을 호출하기 위해 노력하고있어,하지만 어떤 이유 때문에 구문, 그것은 두 번가 호출되는 명령이 수행When 문에서 적절한 리팩토링에 대한 권장 사항은 무엇입니까?
@email = Email.find(params[:id])
delivery = case @email.mail_type
# when "magic_email" these two delayed_jobs perform 2x instead of 1x. Why is that?
when "magic_email" then Delayed::Job.enqueue MagicEmail.new(@email.subject, @email.body)
Delayed::Job.enqueue ReferredEmail.new(@email.subject, @email.body)
when "org_magic_email" then Delayed::Job.enqueue OrgMagicEmail.new(@email.subject, @email.body)
when "all_orgs" then Delayed::Job.enqueue OrgBlast.new(@email.subject, @email.body)
when "all_card_holders" then Delayed::Job.enqueue MassEmail.new(@email.subject, @email.body)
end
return delivery
어떻게 할 수 내가 when "magic_email"
에 도달했을 때, 그것들은 지연된 작업들만을 렌더링하도록합니다. ?
나는 'then'이 있는지 몰랐다. 당신이'배달'으로 무엇을하고 있는지 물어봐도 될까요? case 문이 끝난 후에도 값이 있습니까? – Wukerplank
끝에 답을 추가하는 것을 잊어 버렸습니다. 이런 식으로이 메소드가 실행될 때, 그것은 지연된 : : 그것이 속한 작업을 수행한다. – Trip