0
我一直在使用Enum.reduce
增加日期
Enum.reduce(email_array, {[], [], []}, fn email, {shares, share_requests, changes} = _acc ->
end)
我會在每個減速器傳遞方法
CameraActivity.log_activity(caller, camera, "shared", %{with: email, ip: requester_ip}, done_at)
在done_at,默認值是Ecto.DateTime.utc
,但我想在每個Enum.reduce上增加這個日期和時間。
我試圖在Enum.reduce的最開始處聲明datetime爲done_at = Ecto.DateTime.utc
,但是我不知道如何在Enum.reduce
中循環它,以便我可以增加幾秒鐘進入它。這隻會改變每次迭代的活動時間。任何幫助將不勝感激感謝
更新Dogbert
Enum.reduce(email_array, {[], [], []}, fn email, {shares, share_requests, changes} = _acc ->
with {:found_user, sharee} <- ensure_user(email)
do
case CameraShare.create_share(camera, sharee, caller, params["rights"], params["message"]) do
{:ok, camera_share} ->
unless caller == sharee do
send_email_notification(caller, camera, sharee.email, camera_share.message)
end
Camera.invalidate_user(sharee)
Camera.invalidate_camera(camera)
CameraActivity.log_activity(caller, camera, "shared", %{with: sharee.email, ip: requester_ip})
{[camera_share | shares], share_requests, changes}
{:error, changeset} ->
{shares, share_requests, [attach_email_to_message(changeset, email) | changes]}
end
else
{:not_found, email} ->
case CameraShareRequest.create_share_request(camera, email, caller, params["rights"], params["message"]) do
{:ok, camera_share_request} ->
send_email_notification(caller, camera, email, camera_share_request.message, camera_share_request.key)
CameraActivity.log_activity(caller, camera, "shared", %{with: email, ip: requester_ip})
Intercom.intercom_activity(Application.get_env(:evercam_media, :create_intercom_user), get_user_model(email), get_user_agent(conn), requester_ip, "Shared-Non-Registered")
{shares, [camera_share_request | share_requests], changes}
{:error, changeset} ->
{shares, share_requests, [attach_email_to_message(changeset, email) | changes]}
end
end
end)
你爲什麼不保存'done_at'的電流值在累加器以及在每次迭代增量呢? – Dogbert
我只擔心增量。怎麼做? –
也不知道如何將它保存在累加器中,實際上累加器也是從您以前的問題中學習到的 –