Skip to content

Commit 176d921

Browse files
committed
Run tasks every minute as needed
Clear logs every month (configurable) for old tasks logs.
1 parent 6731f7f commit 176d921

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ APP_DEBUG=false
33
APP_KEY=SomeRandomString3232RandomString
44
APP_THEME=default
55
APP_TIMEZONE=UTC
6+
APP_CLEAR_TASKLOG=720
67

78
DB_HOST=localhost
89
DB_PORT=3306

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111
* Setup scripts (user, mail, env) now support argument flags for use in containers and other non-terminal environments.
1212
* New API endpoints for individual users to control their servers with at `/api/me/*`.
1313
* Typeahead support for owner email when adding a new server.
14+
* Scheduled command to clear out task log every month (configurable timespan).
1415

1516
### Changed
1617
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.
@@ -21,6 +22,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
2122

2223
### Fixed
2324
* Server overview listing the location short-code as the name of the node.
25+
* Server task manager only sending commands every 5 minutes at the quickest.
2426

2527
## v0.5.0-pre.2 (Bodacious Boreopterus)
2628

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
namespace Pterodactyl\Console\Commands;
25+
26+
use DB;
27+
use Carbon;
28+
use Pterodactyl\Models;
29+
use Illuminate\Console\Command;
30+
use Illuminate\Foundation\Bus\DispatchesJobs;
31+
32+
use Pterodactyl\Jobs\SendScheduledTask;
33+
34+
class ClearTasks extends Command
35+
{
36+
37+
use DispatchesJobs;
38+
39+
/**
40+
* The name and signature of the console command.
41+
*
42+
* @var string
43+
*/
44+
protected $signature = 'pterodactyl:tasks:clearlog';
45+
46+
/**
47+
* The console command description.
48+
*
49+
* @var string
50+
*/
51+
protected $description = 'Clears old log entires (> 2 months) from the last log.';
52+
53+
/**
54+
* Create a new command instance.
55+
*
56+
* @return void
57+
*/
58+
public function __construct()
59+
{
60+
parent::__construct();
61+
}
62+
63+
/**
64+
* Execute the console command.
65+
*
66+
* @return mixed
67+
*/
68+
public function handle()
69+
{
70+
$entries = Models\TaskLog::where('run_time', '<=', Carbon::now()->subHours(env('APP_CLEAR_TASKLOG', 720))->toAtomString())->get();
71+
72+
$this->info(sprintf('Preparing to delete %d old task log entries.', count($entries)));
73+
$bar = $this->output->createProgressBar(count($entries));
74+
75+
foreach ($entries as &$entry) {
76+
$entry->delete();
77+
$bar->advance();
78+
}
79+
80+
$bar->finish();
81+
$this->info("\nFinished deleting old logs.");
82+
}
83+
}

app/Console/Kernel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
1818
\Pterodactyl\Console\Commands\ShowVersion::class,
1919
\Pterodactyl\Console\Commands\UpdateEnvironment::class,
2020
\Pterodactyl\Console\Commands\RunTasks::class,
21+
\Pterodactyl\Console\Commands\ClearTasks::class,
2122
\Pterodactyl\Console\Commands\ClearServices::class,
2223
\Pterodactyl\Console\Commands\UpdateEmailSettings::class,
2324
];
@@ -30,6 +31,7 @@ class Kernel extends ConsoleKernel
3031
*/
3132
protected function schedule(Schedule $schedule)
3233
{
33-
$schedule->command('pterodactyl:tasks')->everyFiveMinutes()->withoutOverlapping();
34+
$schedule->command('pterodactyl:tasks')->everyMinute()->withoutOverlapping();
35+
$schedule->command('pterodactyl:tasks:clearlog')->twiceDaily(3, 15);
3436
}
3537
}

0 commit comments

Comments
 (0)