summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/worker.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-03 18:26:05 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-03 18:26:05 +0200
commitb4bb68b7c328742cb49f517d90ea46c75ee2979d (patch)
tree0e9c386f04d8ce50555070435a469ed5183cf91b /lib/Travelynx/Command/worker.pm
parent545796c4a1ab9f4832301a953506f6b3a11b736c (diff)
Add worker command for Docker setups (#9)
Diffstat (limited to 'lib/Travelynx/Command/worker.pm')
-rw-r--r--lib/Travelynx/Command/worker.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Travelynx/Command/worker.pm b/lib/Travelynx/Command/worker.pm
new file mode 100644
index 0000000..6b70f2e
--- /dev/null
+++ b/lib/Travelynx/Command/worker.pm
@@ -0,0 +1,36 @@
+package Travelynx::Command::worker;
+use Mojo::Base 'Mojolicious::Command';
+use Mojo::IOLoop;
+
+has description =>
+ 'travelynx background worker';
+
+has usage => sub { shift->extract_usage };
+
+sub run {
+ my ($self) = @_;
+
+ Mojo::IOLoop->recurring(180 => sub {
+ $self->app->start('work');
+ });
+
+ Mojo::IOLoop->recurring(3600 => sub {
+ $self->app->start('maintenance');
+ });
+
+ if (not Mojo::IOLoop->is_running) {
+ Mojo::IOLoop->start;
+ }
+}
+
+1;
+
+__END__
+
+=head1 SYNOPSIS
+
+ Usage: index.pl worker
+
+ Background worker for cron-less setups, e.g. Docker.
+
+ Calls "index.pl work" every 3 minutes and "index.pl maintenance" every 1 hour.