Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
New script to "scrub" the envoy notice queue for a given notify cycle.
Browse files Browse the repository at this point in the history
This is basically the same as the envoy cron job, except it skips mailing.
  • Loading branch information
jbarrett committed Jun 13, 2014
1 parent c20b8b7 commit f1fce37
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
50 changes: 26 additions & 24 deletions lib/DDGC/Web/Controller/Cronjob.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 32 additions & 0 deletions script/ddgc_scrub_envoy_notify_cycle.pl
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 );

0 comments on commit f1fce37

Please sign in to comment.