Skip to content
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

[WIP] notification of share through email moved to background job #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharidas
Copy link
Contributor

It is better to move the notification of share using
email to background job. This prevents timeout or long
time wait to notify the user(s).

Signed-off-by: Sujith H [email protected]

@sharidas sharidas self-assigned this Jul 30, 2018
@sharidas sharidas added this to the development milestone Jul 30, 2018
@sharidas sharidas force-pushed the email-notification-background branch from adbbc02 to f575504 Compare July 30, 2018 16:27
@sharidas sharidas force-pushed the email-notification-background branch from f575504 to dde984e Compare July 31, 2018 06:02
@codecov-io
Copy link

codecov-io commented Jul 31, 2018

Codecov Report

Merging #217 into master will decrease coverage by 0.47%.
The diff coverage is 85.71%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #217      +/-   ##
============================================
- Coverage     89.55%   89.07%   -0.48%     
- Complexity      134      161      +27     
============================================
  Files            18       19       +1     
  Lines           536      604      +68     
============================================
+ Hits            480      538      +58     
- Misses           56       66      +10
Flag Coverage Δ Complexity Δ
#phpunit 89.07% <85.71%> (-0.48%) 161 <28> (+27)
Impacted Files Coverage Δ Complexity Δ
lib/App.php 100% <100%> (ø) 5 <2> (+1) ⬆️
lib/BackgroundJob/MailNotificationSender.php 84.37% <84.37%> (ø) 26 <26> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00abb1d...a3aae6b. Read the comment docs.

It is better to move the notification of share using
email to background job. This prevents timeout or long
time wait to notify the user(s).

Signed-off-by: Sujith H <[email protected]>
@sharidas sharidas force-pushed the email-notification-background branch from dde984e to a3aae6b Compare July 31, 2018 06:45
@jvillafanez
Copy link
Member

Do we want to move all these notifications to the background job? I expected to use the background job only for big groups...

@sharidas
Copy link
Contributor Author

Do we want to move all these notifications to the background job? I expected to use the background job only for big groups...

@jvillafanez Only email notifications are moved to background jobs. When user tries to share a file/folder to a group/user the notification to the user(s) would be received normally ( as that part is not touched ).

* @param string $shareFullId
* @return null
*/
public function emailNotify($shareFullId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently unused

$this->mailer = $mailer ? $mailer : \OC::$server->getMailer();
$this->config = $config ? $config : \OC::$server->getConfig();

$optionsStorage = new OptionsStorage($this->config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better rely on DI

* @param $notificationURL
* @return string
*/
public function fixURL($notificationURL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

*
* @package OCA\Notifications\BackgroundJob
*/
class MailNotificationSender extends Job {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either extend the (private) QueuedJob class or implement the public interface.

/**
* @param $shareFullId
*/
public function sendNotify($shareFullId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless there is a reason to call this method from the outside, keep the method private

$users = [];
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Notify all the group members
$group = $this->groupManager->get($share->getSharedWith());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the group doesn't exist? it might have been deleted after the notification was generated

$users = $group->getUsers();
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$users[] = $this->userManager->get($share->getSharedWith());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abort the function if it doesn't match any of those share types? This way is clearer that we are handling this case.


foreach ($users as $user) {
if ($user->getEMailAddress() === null) {
\OC::$server->getLogger()->warning("Mail notification can not be sent to " . $user->getUID() . " for share " . $share->getName() . " as email for user is not set");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the injected logger

$acceptAction->setLink($fileLink, 'POST');
$notification->addAction($acceptAction);

if (\count($notificationList) < $maxCountSendNotification) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make a difference to send the emails like this? It took a while to understand what you're doing here. Sending the emails one by one would be easier, so unless there is a real advantage I'd prefer to go through the easy route.

} else {
$this->sendNotify($this->getArgument()['shareFullId']);
}
\OC::$server->getJobList()->removeById($this->getId());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, better use the QueuedJob and let it handle this by itself.

@PVince81 PVince81 modified the milestones: development, backlog Aug 21, 2018
@PVince81 PVince81 assigned sharidasan and unassigned sharidas Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants