Switch to tmpreaper for Ansible installs.
This commit is contained in:
parent
3dcc087487
commit
1186627d4f
|
@ -30,7 +30,6 @@ class SyncProvider implements ServiceProviderInterface
|
|||
]),
|
||||
new \Pimple\ServiceIterator($di, [
|
||||
// Every hour tasks
|
||||
Task\TempCleanup::class,
|
||||
Task\Analytics::class,
|
||||
Task\RadioAutomation::class,
|
||||
Task\HistoryCleanup::class,
|
||||
|
@ -118,13 +117,5 @@ class SyncProvider implements ServiceProviderInterface
|
|||
$di[\Supervisor\Supervisor::class]
|
||||
);
|
||||
};
|
||||
|
||||
$di[Task\TempCleanup::class] = function($di) {
|
||||
return new Task\TempCleanup(
|
||||
$di[\Doctrine\ORM\EntityManager::class],
|
||||
$di[\Monolog\Logger::class],
|
||||
$di[\App\Radio\Filesystem::class]
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
namespace App\Sync\Task;
|
||||
|
||||
use App\Radio\Filesystem;
|
||||
use Doctrine\Common\Persistence\Mapping\MappingException;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use App\Entity;
|
||||
use Monolog\Logger;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class TempCleanup extends AbstractTask
|
||||
{
|
||||
const DELETE_THRESHOLD = 43200;
|
||||
|
||||
/** @var Filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param Logger $logger
|
||||
* @param Filesystem $filesystem
|
||||
*
|
||||
* @see \App\Provider\SyncProvider
|
||||
*/
|
||||
public function __construct(EntityManager $em, Logger $logger, Filesystem $filesystem)
|
||||
{
|
||||
parent::__construct($em, $logger);
|
||||
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
|
||||
public function run($force = false): void
|
||||
{
|
||||
$station_repo = $this->em->getRepository(Entity\Station::class);
|
||||
$stations = $station_repo->findAll();
|
||||
|
||||
foreach ($stations as $station) {
|
||||
$this->cleanUpTempDir($station);
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanUpTempDir(Entity\Station $station): void
|
||||
{
|
||||
$fs = $this->filesystem->getForStation($station);
|
||||
$fs->flushAllCaches();
|
||||
|
||||
$threshold = time() - self::DELETE_THRESHOLD;
|
||||
|
||||
$deleted = 0;
|
||||
$preserved = 0;
|
||||
|
||||
foreach($fs->listContents('temp://', false) as $file) {
|
||||
$file_uri = 'temp://'.$file['path'];
|
||||
|
||||
if ($file['timestamp'] < $threshold) {
|
||||
if ('file' === $file['type']) {
|
||||
$fs->delete($file_uri);
|
||||
} else {
|
||||
$fs->deleteDir($file_uri);
|
||||
}
|
||||
|
||||
$deleted++;
|
||||
} else {
|
||||
$preserved++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->debug(sprintf('Temp file cleanup for station "%s"', $station->getName()), [
|
||||
'deleted' => $deleted,
|
||||
'preserved' => $preserved,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ else
|
|||
fi
|
||||
|
||||
APP_ENV="${APP_ENV:-production}"
|
||||
UPDATE_REVISION="${UPDATE_REVISION:-40}"
|
||||
UPDATE_REVISION="${UPDATE_REVISION:-41}"
|
||||
|
||||
echo "Updating AzuraCast (Environment: $APP_ENV, Update revision: $UPDATE_REVISION)"
|
||||
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
---
|
||||
- name: Install cron-related packages
|
||||
apt:
|
||||
name: "{{ packages }}"
|
||||
state: latest
|
||||
vars:
|
||||
packages:
|
||||
- cron
|
||||
- tmpreaper
|
||||
|
||||
- name: Generate Cron Template
|
||||
template: src=azuracast_cron.j2 dest="{{ tmp_base }}/azuracast_cron" force=true
|
||||
|
||||
|
@ -7,4 +16,4 @@
|
|||
notify: restart cron
|
||||
|
||||
- name: Clean up temp Cron file
|
||||
file: path="{{ tmp_base }}/azuracast_cron" state=absent
|
||||
file: path="{{ tmp_base }}/azuracast_cron" state=absent
|
||||
|
|
|
@ -6,3 +6,4 @@
|
|||
* * * * * sleep 15; php {{ util_base }}/cli.php sync:run nowplaying
|
||||
* * * * * sleep 30; php {{ util_base }}/cli.php sync:run nowplaying
|
||||
* * * * * sleep 45; php {{ util_base }}/cli.php sync:run nowplaying
|
||||
0 */6 * * * tmpreaper 12h /var/azuracast/stations/*/temp
|
||||
|
|
|
@ -24,5 +24,5 @@
|
|||
- { role: ufw, when: update_revision|int < 12 }
|
||||
- { role: maxmind, when: update_revision|int < 24 }
|
||||
- { role: services, when: update_revision|int < 13 }
|
||||
- { role: azuracast-cron, when: update_revision|int < 34 }
|
||||
- { role: azuracast-cron, when: update_revision|int < 41 }
|
||||
- azuracast-setup
|
||||
|
|
Loading…
Reference in New Issue