Skip to content

Commit

Permalink
Screenshot download
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Nov 21, 2021
1 parent ad1329a commit 5068a4f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
24 changes: 12 additions & 12 deletions .docker/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ services:
volumes:
- ./etc/schema.sql:/docker-entrypoint-initdb.d/000_schema.sql:ro
- blogdb_database:/var/lib/postgresql/data
# minion-database:
# image: postgres:11
# container_name: meshmage-minion-db
# ports:
# - 127.0.0.1:5433:5432
# environment:
# - POSTGRES_PASSWORD=minion
# - POSTGRES_USER=minion
# - POSTGRES_DB=minion
# volumes:
# - minion_database:/var/lib/postgresql/data
minion-database:
image: postgres:11
container_name: blogdb-minion
ports:
- 127.0.0.1:5400:5432
environment:
- POSTGRES_PASSWORD=minion
- POSTGRES_USER=minion
- POSTGRES_DB=minion
volumes:
- minion_database:/var/lib/postgresql/data


volumes:
blogdb_database:
# minion_database:
minion_database:
1 change: 1 addition & 0 deletions Web/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ requires 'Mojolicious::Plugin::RenderFile';
requires 'Mojo::Pg';
requires 'DateTime::Format::Pg';
requires 'BlogDB::DB';
requires 'WebService::WsScreenshot';

test_requires "Test::Postgresql58";
test_requires "Test::More";
Expand Down
2 changes: 2 additions & 0 deletions Web/lib/BlogDB/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ sub startup ($self) {
$c->stash->{template} = sprintf( "%s/%s", $c->config->{template_dir}, $name );
});

$self->plugin( 'BlogDB::Web::Plugin::MinionTasks');

# Get the router.
my $router = $self->routes;

Expand Down
3 changes: 3 additions & 0 deletions Web/lib/BlogDB/Web/Controller/Blog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ sub post_new_blog ($c) {
),
});

$c->minion->enqueue( download_screenshot => [ $blog->url, $blog->id ] );


#$c->redirect_to( $c->url_for( 'do_blog_edit', id => $blog->id, title => 'new' ) );
}

Expand Down
24 changes: 24 additions & 0 deletions Web/lib/BlogDB/Web/Plugin/MinionTasks.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package BlogDB::Web::Plugin::MinionTasks;
use Mojo::Base 'Mojolicious::Plugin', -signatures;
use WebService::WsScreenshot;
use Minion;

sub register ( $self, $app, $config ) {

my $screenshot = WebService::WsScreenshot->new(
base_url => $app->config->{ws_screenshot}->{base_url},
);

$app->plugin( Minion => { Pg => $app->config->{database}->{minion} } );
$app->plugin( 'Minion::Admin' );

$app->minion->add_task(download_screenshot => sub ( $job, $blog_url, $blog_id ) {
$screenshot->store_screenshot(
url => $blog_url,
out_file => $job->app->config->{ws_screenshot}->{datadir} . "$blog_id.jpg",
);
});

}

1;

0 comments on commit 5068a4f

Please sign in to comment.