You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading from Pigeon.LegacyFCM to Pigeon.FCM, there is a massive spike in CPU usage when sending push notifications to 7000+ devices.
Here is the new Pigeon 2 code:
defsend_push_message_media_music_now(push_message: %PushMessage{}=message,media_music_uuid: media_music_uuid,org_id: org_id)docaseRepo.get_by(MediaMusic,uuid: media_music_uuid)donil->Logger.info("could not find media music with id: #{inspect(%{attributes: media_music_uuid})}")media_music->Logger.info("found media music with id: #{inspect(%{attributes: media_music_uuid})}")caseEcto.Query.from(cinClientDevice,where: c.org_id==^org_id)|>Repo.all()donil->Logger.info("could not find client devices with org_id: #{inspect(%{attributes: org_id})}")client_devices-># do_send_push_message(client_devices, message)tokens=Enum.map(client_devices,fnx->x.firebase_tokenend)chunked_tokens=Enum.chunk_every(tokens,500)Enum.each(chunked_tokens,fnchunk->Logger.info("chunk length #{inspect(%{attributes: length(chunk)})}")data_map=%{"push_message_uuid"=>message.uuid,"deep_link_route"=>message.deep_link_route,"short_url"=>message.short_url,"media_type"=>message.media_type,"media_format"=>media_music.media_format,"media_path"=>message.media_path,"media_url"=>message.media_url,"media_id"=>message.media_id,"thumbnail_path"=>message.thumbnail_path,"thumbnail_url"=>message.thumbnail_url,# "mutable-content" => true,"version"=>"1.3"}Enum.each(chunk,fnx->n=Pigeon.FCM.Notification.new({:token,x},%{"title"=>message.title,"body"=>message.message},data_map)# dbg(n)push=FaithfulWord.FCM.push(n)# dbg(push)end)end)endendend
Previously we would use the convenient handle_push() update() remove() put_mutable_content() put_content_available() found in LegacyFCM, but they are no longer there.
Any suggestions as to what I’m doing wrong here?
Here is the previous code that would not cause a cpu spike:
defsend_push_message_media_music_now(push_message: %PushMessage{}=message,media_music_uuid: media_music_uuid,org_id: org_id)docaseRepo.get_by(MediaMusic,uuid: media_music_uuid)donil->Logger.info("could not find media music with id: #{inspect(%{attributes: media_music_uuid})}")media_music->Logger.info("found media music with id: #{inspect(%{attributes: media_music_uuid})}")caseEcto.Query.from(cinClientDevice,where: c.org_id==^org_id)|>Repo.all()donil->Logger.info("could not find client devices with org_id: #{inspect(%{attributes: org_id})}")client_devices-># do_send_push_message(client_devices, message)tokens=Enum.map(client_devices,fnx->x.firebase_tokenend)chunked_tokens=Enum.chunk_every(tokens,500)Enum.each(chunked_tokens,fnchunk->Logger.info("chunk length #{inspect(%{attributes: length(chunk)})}")chunk|>Pigeon.LegacyFCM.Notification.new()|>Pigeon.LegacyFCM.Notification.put_notification(%{"title"=>message.title,"body"=>message.message})|>Pigeon.LegacyFCM.Notification.put_data(%{"push_message_uuid"=>message.uuid,"deep_link_route"=>message.deep_link_route,"short_url"=>message.short_url,"media_type"=>message.media_type,"media_format"=>media_music.media_format,"media_path"=>message.media_path,"media_url"=>message.media_url,"media_id"=>message.media_id,"thumbnail_path"=>message.thumbnail_path,"thumbnail_url"=>message.thumbnail_url,"mutable-content"=>true,"version"=>"1.3"})|>Pigeon.LegacyFCM.Notification.put_mutable_content(true)|>Pigeon.LegacyFCM.Notification.put_content_available(true)|>Pigeon.LegacyFCM.push(on_response: &handle_push/1)end)endendend
defhandle_push(%Pigeon.LegacyFCM.Notification{status: :success}=notif)doto_update=Pigeon.LegacyFCM.Notification.update?(notif)Logger.info("handle_push to_update #{inspect(%{attributes: to_update})}")to_remove=Pigeon.LegacyFCM.Notification.remove?(notif)Logger.info("handle_push to_remove #{inspect(%{attributes: to_remove})}")Enum.each(to_remove,fnremove_token->caseget_client_device_for_token(remove_token)donil->{:error,"invalid_client_device_token"}remove_device->Repo.delete(remove_device)Logger.info(fn->"Device #{remove_device.id} for token #{remove_device.firebase_token} has been removed"end){:ok,remove_token}endend)# do the reg ID update and deletesenddefhandle_push(%Pigeon.LegacyFCM.Notification{status: other_error})do# some other error happenedLogger.info("handle_push other_error #{inspect(%{attributes: other_error})}")end
The text was updated successfully, but these errors were encountered:
Environment
elixir --version
): elixir:1.14.4-erlang-25.3-alpine-3.17.2After upgrading from Pigeon.LegacyFCM to Pigeon.FCM, there is a massive spike in CPU usage when sending push notifications to 7000+ devices.
Here is the new Pigeon 2 code:
Previously we would use the convenient handle_push() update() remove() put_mutable_content() put_content_available() found in LegacyFCM, but they are no longer there.
Any suggestions as to what I’m doing wrong here?
Here is the previous code that would not cause a cpu spike:
The text was updated successfully, but these errors were encountered: