forked from protonemedia/eddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install cron to cleanup working directories
- Loading branch information
1 parent
0d4e699
commit 3141e15
Showing
7 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Server; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class InstallTaskCleanupCron implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public Server $server) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$workingDirectory = $this->server->working_directory; | ||
|
||
$command = implode(' ; ', [ | ||
"find /root/{$workingDirectory} -name \"task-*\" -type f -mtime +7 -exec rm {} \;", | ||
"find /home/eddy/{$workingDirectory} -name \"task-*\" -type f -mtime +7 -exec rm {} \;", | ||
]); | ||
|
||
$this->server->uploadAsRoot( | ||
'/etc/cron.d/eddy-tasks-cleanup', | ||
view('tasks.eddy-tasks-cleanup', ['command' => $command])->render() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SHELL=/bin/sh | ||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
|
||
{{ $cron->expression }} {{ $cron->user }} {{ $cron->command }} > {{ $cron->logPath() }} 2>&1 | ||
{{ $cron->expression }} {{ $cron->user }} {!! $cron->command !!} > {{ $cron->logPath() }} 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SHELL=/bin/sh | ||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
|
||
0 0 * * * root ({!! $command !!}) 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Jobs; | ||
|
||
use App\Jobs\InstallTaskCleanupCron; | ||
use App\Models\Server; | ||
use App\Tasks\UploadFile; | ||
use Database\Factories\ServerFactory; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use ProtoneMedia\LaravelTaskRunner\Facades\TaskRunner; | ||
use Tests\TestCase; | ||
|
||
class InstallTaskCleanupCronTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function it_uploads_the_cron_file() | ||
{ | ||
TaskRunner::fake(); | ||
|
||
/** @var Server */ | ||
$server = ServerFactory::new()->create(); | ||
|
||
$job = new InstallTaskCleanupCron($server); | ||
$job->handle(); | ||
|
||
TaskRunner::assertDispatched(function (UploadFile $task) { | ||
$this->assertMatchesSnapshot($task->contents); | ||
|
||
return $task->path === '/etc/cron.d/eddy-tasks-cleanup'; | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/Unit/Jobs/__snapshots__/InstallTaskCleanupCronTest__it_uploads_the_cron_file__1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SHELL=/bin/sh | ||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
|
||
0 0 * * * root (find /root/.eddy -name "task-*" -type f -mtime +7 -exec rm {} \; ; find /home/eddy/.eddy -name "task-*" -type f -mtime +7 -exec rm {} \;) 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters