This commit is contained in:
2021-04-16 11:36:27 +08:00
parent 1e16803814
commit 2e8276ca83
2 changed files with 22 additions and 8 deletions
+18 -4
View File
@@ -10,7 +10,6 @@ use Database\ActiveRecord;
use Database\Collection;
use Exception;
use HttpServer\IInterface\Task;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Abstracts\Config;
@@ -223,6 +222,19 @@ class Snowflake
}
/**
* @return bool
*/
public static function isDcoker(): bool
{
exec('ls -alh /.dockerenv', $output, $cod);
if ($cod === 0 && !empty($output)) {
return true;
}
return false;
}
/**
* @param $workerId
* @return mixed
@@ -230,10 +242,13 @@ class Snowflake
*/
public static function setWorkerId($workerId): mixed
{
if (empty($workerId)) {
if (empty($workerId) || static::isDcoker()) {
return $workerId;
}
return self::writeFile(storage($workerId . '.sock', 'pid/worker'), $workerId);
$tmpFile = storage($workerId . '.sock', 'pid/worker');
return self::writeFile($tmpFile, $workerId);
}
@@ -504,7 +519,6 @@ class Snowflake
}
/**
* @return string|null
*/