This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New script to "scrub" the envoy notice queue for a given notify cycle.
This is basically the same as the envoy cron job, except it skips mailing.
- Loading branch information
Showing
2 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,15 @@ sub base :Chained('/base') :PathPart('cronjob') :CaptureArgs(0) { | |
} | ||
|
||
sub index :Chained('base') :PathPart('') :Args { | ||
my ( $self, $c, @args ) = @_; | ||
if ($args[0] eq 'notify_cycle') { | ||
$self->notify_cycle($c,$args[1]); | ||
my ( $self, $c, %args ) = @_; | ||
if ($args{'notify_cycle'}) { | ||
$self->notify_cycle($c,$args{'notify_cycle'}, $args{'scrub'}); | ||
} | ||
$c->response->body('OK'); | ||
} | ||
|
||
sub notify_cycle { | ||
my ( $self, $c, $cycle ) = @_; | ||
my ( $self, $c, $cycle, $skip_notify ) = @_; | ||
$c->stash->{c} = $c; | ||
$c->stash->{u} = sub { | ||
my @args; | ||
|
@@ -62,32 +62,34 @@ sub notify_cycle { | |
$c->d->as($user,sub { | ||
$c->stash->{unsent_notifications_results} = [$user->unsent_notifications_cycle($cycle)->all]; | ||
$c->stash->{unsent_notifications_count} = scalar @{$c->stash->{unsent_notifications_results}}; | ||
try { | ||
$c->d->postman->template_mail( | ||
$user->data->{email}, | ||
'"DuckDuckGo Community Envoy" <[email protected]>', | ||
'[DuckDuckGo Community] '.$c->stash->{unsent_notifications_count}.' new notifications for you', | ||
'notifications', | ||
$c->stash, | ||
); | ||
} | ||
catch { | ||
unless ($skip_notify) { | ||
try { | ||
$c->d->errorlog("Mailing notifications to " . | ||
$user->data->{email} . " failed, mailing " . $c->d->config->error_email); | ||
$c->d->postman->mail( | ||
$c->d->config->error_email, | ||
$c->d->postman->template_mail( | ||
$user->data->{email}, | ||
'"DuckDuckGo Community Envoy" <[email protected]>', | ||
'[DuckDuckGo Community] ERROR ON ENVOY', | ||
$_, | ||
'[DuckDuckGo Community] '.$c->stash->{unsent_notifications_count}.' new notifications for you', | ||
'notifications', | ||
$c->stash, | ||
); | ||
} | ||
catch { | ||
$c->d->errorlog("Failed to mail error report about mailing " . | ||
$c->stash->{unsent_notifications_count} . " notifications to " . | ||
$user->data->{email}); | ||
try { | ||
$c->d->errorlog("Mailing notifications to " . | ||
$user->data->{email} . " failed, mailing " . $c->d->config->error_email); | ||
$c->d->postman->mail( | ||
$c->d->config->error_email, | ||
'"DuckDuckGo Community Envoy" <[email protected]>', | ||
'[DuckDuckGo Community] ERROR ON ENVOY', | ||
$_, | ||
); | ||
} | ||
catch { | ||
$c->d->errorlog("Failed to mail error report about mailing " . | ||
$c->stash->{unsent_notifications_count} . " notifications to " . | ||
$user->data->{email}); | ||
}; | ||
}; | ||
}; | ||
} | ||
my @ids; | ||
for (@{$c->stash->{unsent_notifications_results}}) { | ||
for ($_->event_notifications) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env perl | ||
|
||
$|=1; | ||
|
||
use FindBin; | ||
use lib $FindBin::Dir . "/../lib"; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use DDGC::Config; | ||
|
||
my $cycle = shift @ARGV; | ||
|
||
die "Need cycle!" unless $cycle; | ||
die "Unknown cycle!" unless $cycle >= 1 && $cycle <= 4; | ||
|
||
print "This will CLEAR ALL pending notifications from cycle $cycle, continue (y/n)? "; | ||
my $continue = lc <STDIN>; | ||
die "Bailing out" unless ($continue =~ /^y/); | ||
|
||
$ENV{DDGC_EXECUTE_CRONJOBS} = 'YES'; | ||
|
||
my $base = DDGC::Config->new->web_base; | ||
|
||
use Catalyst::Test qw( DDGC::Web ); | ||
|
||
my $response = request($base.'/cronjob/notify_cycle/'.$cycle."/scrub/1"); | ||
|
||
print $response->content; | ||
|
||
exit ( $response->is_success ? 0 : 1 ); |