Skip to content

Commit 5068a4f

Browse files
committed
Screenshot download
1 parent ad1329a commit 5068a4f

5 files changed

Lines changed: 42 additions & 12 deletions

File tree

.docker/database.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ services:
1313
volumes:
1414
- ./etc/schema.sql:/docker-entrypoint-initdb.d/000_schema.sql:ro
1515
- blogdb_database:/var/lib/postgresql/data
16-
# minion-database:
17-
# image: postgres:11
18-
# container_name: meshmage-minion-db
19-
# ports:
20-
# - 127.0.0.1:5433:5432
21-
# environment:
22-
# - POSTGRES_PASSWORD=minion
23-
# - POSTGRES_USER=minion
24-
# - POSTGRES_DB=minion
25-
# volumes:
26-
# - minion_database:/var/lib/postgresql/data
16+
minion-database:
17+
image: postgres:11
18+
container_name: blogdb-minion
19+
ports:
20+
- 127.0.0.1:5400:5432
21+
environment:
22+
- POSTGRES_PASSWORD=minion
23+
- POSTGRES_USER=minion
24+
- POSTGRES_DB=minion
25+
volumes:
26+
- minion_database:/var/lib/postgresql/data
2727

2828

2929
volumes:
3030
blogdb_database:
31-
# minion_database:
31+
minion_database:

Web/cpanfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ requires 'Mojolicious::Plugin::RenderFile';
44
requires 'Mojo::Pg';
55
requires 'DateTime::Format::Pg';
66
requires 'BlogDB::DB';
7+
requires 'WebService::WsScreenshot';
78

89
test_requires "Test::Postgresql58";
910
test_requires "Test::More";

Web/lib/BlogDB/Web.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ sub startup ($self) {
3232
$c->stash->{template} = sprintf( "%s/%s", $c->config->{template_dir}, $name );
3333
});
3434

35+
$self->plugin( 'BlogDB::Web::Plugin::MinionTasks');
36+
3537
# Get the router.
3638
my $router = $self->routes;
3739

Web/lib/BlogDB/Web/Controller/Blog.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ sub post_new_blog ($c) {
7474
),
7575
});
7676

77+
$c->minion->enqueue( download_screenshot => [ $blog->url, $blog->id ] );
78+
79+
7780
#$c->redirect_to( $c->url_for( 'do_blog_edit', id => $blog->id, title => 'new' ) );
7881
}
7982

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package BlogDB::Web::Plugin::MinionTasks;
2+
use Mojo::Base 'Mojolicious::Plugin', -signatures;
3+
use WebService::WsScreenshot;
4+
use Minion;
5+
6+
sub register ( $self, $app, $config ) {
7+
8+
my $screenshot = WebService::WsScreenshot->new(
9+
base_url => $app->config->{ws_screenshot}->{base_url},
10+
);
11+
12+
$app->plugin( Minion => { Pg => $app->config->{database}->{minion} } );
13+
$app->plugin( 'Minion::Admin' );
14+
15+
$app->minion->add_task(download_screenshot => sub ( $job, $blog_url, $blog_id ) {
16+
$screenshot->store_screenshot(
17+
url => $blog_url,
18+
out_file => $job->app->config->{ws_screenshot}->{datadir} . "$blog_id.jpg",
19+
);
20+
});
21+
22+
}
23+
24+
1;

0 commit comments

Comments
 (0)