Add Sync plugins
Add support for synchronising remote content before running the source dispatchers. First plugin adds Rsync support.
This commit is contained in:
@@ -13,12 +13,28 @@ class DownloadDispatcher_Processor {
|
|||||||
$config = $main->config();
|
$config = $main->config();
|
||||||
$log = $main->log();
|
$log = $main->log();
|
||||||
|
|
||||||
// Find the list of available plugins
|
// Find the list of available Sync plugins
|
||||||
|
$sync_plugins = $config->get('sync');
|
||||||
|
foreach ($sync_plugins as $plugin_name) {
|
||||||
|
// Get a list of all the instances of this plugin to be used
|
||||||
|
$instances = $config->get("sync.{$plugin_name}");
|
||||||
|
foreach ($instances as $instance) {
|
||||||
|
try {
|
||||||
|
$plugin = DownloadDispatcher_Sync_PluginFactory::create($plugin_name, $config, $log, $instance);
|
||||||
|
$plugin->run();
|
||||||
|
|
||||||
|
} catch(SihnonFramework_Exception_LogException $e) {
|
||||||
|
SihnonFramework_LogEntry::warning($log, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the list of available source plugins
|
||||||
DownloadDispatcher_Source_PluginFactory::scan();
|
DownloadDispatcher_Source_PluginFactory::scan();
|
||||||
$plugins = DownloadDispatcher_Source_PluginFactory::getValidPlugins();
|
$source_plugins = DownloadDispatcher_Source_PluginFactory::getValidPlugins();
|
||||||
|
|
||||||
$enabled_plugins = $config->get('sources');
|
$enabled_plugins = $config->get('sources');
|
||||||
foreach ($plugins as $plugin_name) {
|
foreach ($source_plugins as $plugin_name) {
|
||||||
if (in_array($plugin_name, $enabled_plugins)) {
|
if (in_array($plugin_name, $enabled_plugins)) {
|
||||||
$plugin = DownloadDispatcher_Source_PluginFactory::create($plugin_name, $config, $log);
|
$plugin = DownloadDispatcher_Source_PluginFactory::create($plugin_name, $config, $log);
|
||||||
$plugin->run();
|
$plugin->run();
|
||||||
|
|||||||
16
source/lib/DownloadDispatcher/Sync/IPlugin.class.php
Normal file
16
source/lib/DownloadDispatcher/Sync/IPlugin.class.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
interface DownloadDispatcher_Sync_IPlugin extends DownloadDispatcher_IPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process files recognised by this plugin
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function run();
|
||||||
|
|
||||||
|
public static function create($config, $log, $instance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
48
source/lib/DownloadDispatcher/Sync/Plugin/Rsync.class.php
Normal file
48
source/lib/DownloadDispatcher/Sync/Plugin/Rsync.class.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Sync_Plugin_Rsync extends DownloadDispatcher_PluginBase implements DownloadDispatcher_Sync_IPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of this plugin
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const PLUGIN_NAME = 'Rsync';
|
||||||
|
|
||||||
|
protected $config;
|
||||||
|
protected $log;
|
||||||
|
|
||||||
|
protected $instance;
|
||||||
|
protected $options;
|
||||||
|
protected $source;
|
||||||
|
protected $destination;
|
||||||
|
|
||||||
|
public static function create($config, $log, $instance) {
|
||||||
|
return new self($config, $log, $instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function __construct($config, $log, $instance) {
|
||||||
|
$this->config = $config;
|
||||||
|
$this->log = $log;
|
||||||
|
$this->instance = $instance;
|
||||||
|
|
||||||
|
$this->options = $this->config->get("sync.Rsync.{$this->instance}.options");
|
||||||
|
$this->source = $this->config->get("sync.Rsync.{$this->instance}.source");
|
||||||
|
$this->destination = $this->config->get("sync.Rsync.{$this->instance}.destination");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
DownloadDispatcher_LogEntry::debug($this->log, "Running Rsync synchroniser: '{$this->instance}'");
|
||||||
|
|
||||||
|
$command = "/usr/bin/rsync {$this->options} '{$this->source}' '{$this->destination}'";
|
||||||
|
DownloadDispatcher_LogEntry::debug($this->log, "Running foreground task: {$command}");
|
||||||
|
|
||||||
|
DownloadDispatcher_ForegroundTask::execute($command, null, null, null, array($this, 'output'), null, $this->instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function output($identifier, $data) {
|
||||||
|
DownloadDispatcher_LogEntry::debug($this->log, "{$identifier}: {$data}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
30
source/lib/DownloadDispatcher/Sync/PluginFactory.class.php
Normal file
30
source/lib/DownloadDispatcher/Sync/PluginFactory.class.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DownloadDispatcher_Sync_PluginFactory extends DownloadDispatcher_PluginFactory {
|
||||||
|
|
||||||
|
protected static $plugin_prefix = 'DownloadDispatcher_Sync_Plugin_';
|
||||||
|
protected static $plugin_interface = 'DownloadDispatcher_Sync_IPlugin';
|
||||||
|
protected static $plugin_dir = array(
|
||||||
|
DownloadDispatcher_Lib => 'DownloadDispatcher/Sync/Plugin/',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create($plugin, SihnonFramework_Config $config, SihnonFramework_Log $log, $instance) {
|
||||||
|
self::ensureScanned();
|
||||||
|
|
||||||
|
if (! self::isValidPlugin($plugin)) {
|
||||||
|
throw new Sihnon_Exception_InvalidPluginName($plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
$classname = self::classname($plugin);
|
||||||
|
|
||||||
|
return call_user_func(array($classname, 'create'), $config, $log, $instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user