-
Notifications
You must be signed in to change notification settings - Fork 54
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
Update notification instance action default accepts #700
Conversation
WalkthroughThe changes involve modifications to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
server/lib/orcasite/notifications/resources/notification_instance.ex (2)
Line range hint
48-71
: Add error handling for Oban job insertion.The
after_action
callback creates an Oban job but doesn't handle potential job insertion failures. This could lead to notifications being marked as processed without actually being sent.Consider wrapping the Oban insertion in error handling:
change fn changeset, _context -> changeset |> Ash.Changeset.after_action(fn _, record -> - %{ - notification_instance_id: record.id, - notification_id: record.notification_id, - subscription_id: record.subscription_id, - meta: record.meta - } - |> Orcasite.Notifications.Workers.SendNotificationEmail.new() - |> Oban.insert() - - {:ok, record} + case %{ + notification_instance_id: record.id, + notification_id: record.notification_id, + subscription_id: record.subscription_id, + meta: record.meta + } + |> Orcasite.Notifications.Workers.SendNotificationEmail.new() + |> Oban.insert() do + {:ok, _job} -> {:ok, record} + {:error, error} -> + # Log the error and potentially update the notification status + {:error, "Failed to queue notification: #{inspect(error)}"} + end end) end
Line range hint
48-71
: Consider adding notification monitoring capabilities.The asynchronous notification processing via Oban is a good architectural choice for scalability. However, consider adding:
- Monitoring for failed notifications
- A mechanism to retry failed notifications
- Metrics collection for notification processing times and success rates
This will help track the health of the notification system and ensure reliable delivery.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
server/lib/orcasite/notifications/resources/notification_instance.ex
(1 hunks)server/lib/orcasite/radio/audio_image.ex
(1 hunks)
🔇 Additional comments (3)
server/lib/orcasite/notifications/resources/notification_instance.ex (2)
Line range hint 48-71
: Verify ExtractNotificationInstanceMeta implementation.
The action uses ExtractNotificationInstanceMeta
for processing meta data, but its implementation needs verification to ensure proper data extraction.
Let's check the implementation:
#!/bin/bash
# Description: Locate and examine the ExtractNotificationInstanceMeta module
# Look for the implementation file
fd -e ex "ExtractNotificationInstanceMeta.ex" server/lib/orcasite/notifications/changes/
# If found, examine its content
rg -A 10 "defmodule.*ExtractNotificationInstanceMeta" server/lib/orcasite/notifications/changes/
46-46
: Verify security implications of wildcard parameters.
The change from explicit actions to update: :*
and create: :*
allows any parameters to be passed. While this fixes the deployment issue, it might expose security risks if not properly validated.
Let's verify if there are adequate validations in place:
✅ Verification successful
Let me gather more information about the validation and constraints by checking the resource definition and related files.
Wildcard parameters are safely constrained by attribute definitions
The use of update: :*
and create: :*
is safe because the resource has well-defined attribute constraints:
:channel
is restricted to[:email]
:status
is restricted to[:new, :pending, :sent, :failed]
- Other attributes have strict types (
:map
,:utc_datetime_usec
) - Relationships are properly defined with
belongs_to
constraints
The Ash framework enforces these constraints automatically, preventing any unauthorized attributes from being set through the wildcard parameters. The change aligns with the deployment requirements while maintaining security.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for validation logic in related files
# Look for validation modules or constraints
rg -g '!*.beam' -g '!*.ex.beam' -A 5 "validate|constraint|guard" server/lib/orcasite/notifications/
Length of output: 1456
Script:
#!/bin/bash
# Check the resource definition for attributes and their constraints
ast-grep --pattern 'defmodule Orcasite.Notifications.NotificationInstance do
$$$
attributes do
$$$
end
$$$
'
# Look for any change modules that might contain validations
rg -g '*.ex' -A 5 "use Ash.Resource.Change|validate" server/lib/orcasite/notifications/
# Check for relationships and their constraints
ast-grep --pattern 'relationships do
$$$
end'
Length of output: 17584
server/lib/orcasite/radio/audio_image.ex (1)
170-170
: Confirm that disabling atomicity is appropriate for this action
By setting require_atomic? false
, the update :generate_spectrogram
action will not run inside a transaction. Since the action involves asynchronous processing, this may be acceptable. However, please verify that transactional guarantees are not needed here to maintain data consistency and prevent race conditions.
Run the following script to examine the usage of require_atomic?
across the codebase:
✅ Verification successful
Based on the search results, I can now generate a final response since I have enough context about how require_atomic?
is used across the codebase.
Setting require_atomic? false
is appropriate for this spectrogram generation action
The codebase consistently uses require_atomic? false
for actions that involve asynchronous processing or external operations. This pattern is seen in similar scenarios:
- Feed stream operations that handle playlist and segment processing
- Notification handling for subscriptions and notifications
- Detection and candidate processing
- Other audio/feed related operations
The spectrogram generation is an asynchronous operation that doesn't require immediate transactional consistency, as evidenced by:
- The action sets the status to
:processing
and uses anafter_action
hook - Similar to other async operations in the codebase that follow this pattern
- No critical data dependencies that would require atomic guarantees
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for all occurrences of `require_atomic?` in action definitions.
# Expected result: Review how `require_atomic?` is used in other actions to ensure consistency.
rg -A 5 $'require_atomic?'
Length of output: 6347
Fixes issue with deployment where notification instances don't have the right attributes accepted:
![image](https://private-user-images.githubusercontent.com/997770/381683806-3a9942e7-60a1-4671-8344-07831491c48a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MzExNjksIm5iZiI6MTczOTYzMDg2OSwicGF0aCI6Ii85OTc3NzAvMzgxNjgzODA2LTNhOTk0MmU3LTYwYTEtNDY3MS04MzQ0LTA3ODMxNDkxYzQ4YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQxNDQ3NDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zMmJkMzg2OTk2MjU5MGViNTJmOGNlODU2YWI4MTBmYzkxYTk5ZmU2ZmVlMGNmZDJjZTRiMmY4NTBiZWIzOTE4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.NaleOIIaEtV3dYkmHWFjfa-EBF7KgYasjWwZh-Wdhac)
Summary by CodeRabbit
New Features
Bug Fixes