fivesqrd / 中央
此包最新版本(1.2.4)没有可用的许可信息。
多服务器实现的中央任务日志库
1.2.4
2018-05-17 10:26 UTC
Requires
- php: >=5.4.0
README
中央控制台脚本日志
composer require fivesqrd/central:1.2.*
设置
使用AWS SDK
$config = [
'namespace' => 'My-App-Name',
'adapter' => 'Aws',
'options' => [ // Adapter specific options
'table' => null,
'client' => new Aws\DynamoDb\DynamoDbClient($aws),
'marshaler' => new Aws\DynamoDb\Marshaler()
],
];
使用Bego库
$db = new Bego\Database(
new Aws\DynamoDb\DynamoDbClient($config), new Aws\DynamoDb\Marshaler()
);
$config = [
'namespace' => 'My-App-Name',
'adapter' => 'Bego',
'options' => [ // Adapter specific options
'client' => $db->table(new App\MyTables\Logs()),
],
];
使用Laravel 5设置,在Laravel中自动完成
基本示例
use Fivesqrd\Central;
$job = Central\Factory::job($config);
$job->instance('MyScriptName')->start(function($log) {
//do something here
$log->debug('Something was done');
return 'Everything was done ok';
});
/* Store log for 30 days */
$job->save(strtotime('+ 30 days'));
/* Get the job status */
echo $job->status();
在类内部执行
use Fivesqrd\Central;
$job = Central\Factory::job($config)
->instance(self::class)
->start(array($this, '_execute'))
->save(strtotime('+ 30 days'));
实时调试输出
/* Output debug info to stdout as well */
print_r($job->log()->toArray());
/* Output the same log entry saved to storage */
print_r($job->record());
原子锁
use Fivesqrd\Central;
$job = Central\Factory::job($config)
->instance(self::class)
->lock()
->start(self::class, array($this, '_execute'))
->save(strtotime('+ 30 days'));
Laravel 5
`.env`需求
CENTRAL_TABLE="My-Table"
CENTRAL_ADAPTER="Aws"
CENTRAL_NAMESPACE="My-App"
AWS_KEY="my-key"
AWS_SECRET="my-secret"
AWS_REGION="eu-west-1"
AWS_ENDPOINT=
在命令类中使用
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$job = resolve('central')
->instance(self::class)
->start(array($this, '_execute'))
->save(strtotime('+ 30 days'));
/* logic here */
$this->info("Command completed with: {$job->status()}");;
}
protected function _execute($log)
{
$log->debug('Job started at ' . date('Y-m-d H:i:s'));
return 'It worked';
}