[dw-free] allow temporary suspends of new imports
[commit: http://hg.dwscoalition.org/dw-free/rev/bd62ae32429f]
http://bugs.dwscoalition.org/show_bug.cgi?id=3601
Allow users to queue, but let us decline to process (and put back into
queue) temporarily. Configurable by site.
Patch by
fu.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3601
Allow users to queue, but let us decline to process (and put back into
queue) temporarily. Configurable by site.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/DW/Worker/ContentImporter.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Bio.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Friends.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Tags.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Verify.pm
-------------------------------------------------------------------------------- diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter.pm --- a/cgi-bin/DW/Worker/ContentImporter.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter.pm Mon Apr 11 02:25:05 2011 +0800 @@ -194,6 +194,35 @@ sub ok { return; } +=head2 C<< $class->decline( $job, %opts ) >> + +Decline to process the job for now. Will retry again later. (Does not count against the maximum number of retries) + +=cut + +sub decline { + my ( $class, $job, %opts ) = @_; + + $opts{delay} ||= 3600 * 24; + $job->run_after( time() + $opts{delay} ); + $job->declined( 1 ); + $job->save(); + + return; +} + +=head2 C<< $class->enabled( $data ) >> + +Check whether this import source is enabled. + +=cut + +sub enabled { + my ( $class, $data ) = @_; + return LJ::is_enabled( "importing", $data->{hostname} ); +} + + =head2 C<< $class->status( $import_data, $item, $args ) >> This creates an LJ::Event::ImportStatus item for the user to look at. Note that $args diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Bio.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Bio.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Bio.pm Mon Apr 11 02:25:05 2011 +0800 @@ -30,6 +30,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm Mon Apr 11 02:25:05 2011 +0800 @@ -36,6 +36,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm Mon Apr 11 02:25:05 2011 +0800 @@ -31,6 +31,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm Mon Apr 11 02:25:05 2011 +0800 @@ -31,6 +31,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Friends.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Friends.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Friends.pm Mon Apr 11 02:25:05 2011 +0800 @@ -29,6 +29,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Tags.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Tags.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Tags.pm Mon Apr 11 02:25:05 2011 +0800 @@ -31,6 +31,8 @@ sub work { my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + return $class->decline( $job ) unless $class->enabled( $data ); + eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { $msg =~ s/\r?\n/ /gs; diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm Mon Apr 11 02:25:05 2011 +0800 @@ -35,6 +35,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { diff -r 4ecb7970cbba -r bd62ae32429f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Verify.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Verify.pm Mon Apr 11 01:57:44 2011 +0800 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Verify.pm Mon Apr 11 02:25:05 2011 +0800 @@ -30,6 +30,8 @@ sub work { my ( $class, $job ) = @_; my $opts = $job->arg; my $data = $class->import_data( $opts->{userid}, $opts->{import_data_id} ); + + return $class->decline( $job ) unless $class->enabled( $data ); eval { try_work( $class, $job, $opts, $data ); }; if ( my $msg = $@ ) { --------------------------------------------------------------------------------