travelynx/lib/Travelynx/Command/worker.pm

44 lines
739 B
Perl
Raw Normal View History

package Travelynx::Command::worker;
2022-02-19 15:32:43 +00:00
2023-02-19 08:35:38 +00:00
# Copyright (C) 2020-2023 Daniel Friesel
2020-11-27 21:12:56 +00:00
#
2021-01-29 17:32:13 +00:00
# SPDX-License-Identifier: AGPL-3.0-or-later
use Mojo::Base 'Mojolicious::Command';
use Mojo::IOLoop;
2022-02-19 15:32:43 +00:00
has description => 'travelynx background worker';
has usage => sub { shift->extract_usage };
sub run {
my ($self) = @_;
2022-02-19 15:32:43 +00:00
Mojo::IOLoop->recurring(
180 => sub {
$self->app->start('work');
}
);
2022-02-19 15:32:43 +00:00
Mojo::IOLoop->recurring(
36000 => sub {
$self->app->start('maintenance');
}
);
2022-02-19 15:32:43 +00:00
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.
2022-02-19 15:32:43 +00:00
Calls "index.pl work" every 3 minutes and "index.pl maintenance" every 10 hours.