Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Reconnect to PostgreSQL on every job
Browse files Browse the repository at this point in the history
The database handler might die out and start skipping all the rest of
the jobs on a single database failure.
  • Loading branch information
pypt committed Aug 10, 2017
1 parent 34971f5 commit 97c110d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
10 changes: 1 addition & 9 deletions lib/MediaWords/Job/AnnotateWithCoreNLP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,12 @@ use MediaWords::Util::CoreNLP;
use MediaWords::DBI::Stories;
use Readonly;

# Having a global database object should be safe because
# job workers don't fork()
my $db = undef;

# Run CoreNLP job
sub run($;$)
{
my ( $self, $args ) = @_;

unless ( $db )
{
# Postpone connecting to the database so that compile test doesn't do that
$db = MediaWords::DB::connect_to_db();
}
my $db = MediaWords::DB::connect_to_db();

my $stories_id = $args->{ stories_id } + 0;
unless ( $stories_id )
Expand Down
7 changes: 1 addition & 6 deletions lib/MediaWords/Job/Bitly/FetchStoryStats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ Readonly my $BITLY_RATE_LIMIT_SECONDS_TO_WAIT => 60 * 10; # every 10 minutes
# How many times to try on rate limiting errors
Readonly my $BITLY_RATE_LIMIT_TRIES => 7; # try fetching 7 times in total (70 minutes)

# Having a global database object should be safe because
# job workers don't fork()
my $db = undef;

# Run job
sub run($;$)
{
my ( $self, $args ) = @_;

# Postpone connecting to the database so that compile test doesn't do that
$db ||= MediaWords::DB::connect_to_db();
my $db = MediaWords::DB::connect_to_db();

my $stories_id = $args->{ stories_id } or die "'stories_id' is not set.";
my $start_timestamp = $args->{ start_timestamp };
Expand Down
7 changes: 1 addition & 6 deletions lib/MediaWords/Job/Facebook/FetchStoryStats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ use MediaWords::Util::Process;
use Readonly;
use Data::Dumper;

# Having a global database object should be safe because
# job workers don't fork()
my $db = undef;

# Run job
sub run($;$)
{
Expand All @@ -47,8 +43,7 @@ sub run($;$)
fatal_error( 'Facebook API processing is not enabled.' );
}

# Postpone connecting to the database so that compile test doesn't do that
$db ||= MediaWords::DB::connect_to_db();
my $db = MediaWords::DB::connect_to_db();

my $stories_id = $args->{ stories_id } or die "'stories_id' is not set.";

Expand Down

0 comments on commit 97c110d

Please sign in to comment.