mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Enable the feature flag for telemetry.
This commit is contained in:
parent
61733f6553
commit
be58b1d2be
@ -94,10 +94,10 @@ class Cron extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fire telemetry cron job (disabled):
|
* Fire telemetry cron job
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
//$this->telemetryCronJob($force, $date);
|
$this->telemetryCronJob($force, $date);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
|
@ -42,6 +42,7 @@ class CronController
|
|||||||
$results = [];
|
$results = [];
|
||||||
$results[] = $this->runRecurring();
|
$results[] = $this->runRecurring();
|
||||||
$results[] = $this->runAutoBudget();
|
$results[] = $this->runAutoBudget();
|
||||||
|
$results[] = $this->runTelemetry();
|
||||||
|
|
||||||
return implode("<br>\n", $results);
|
return implode("<br>\n", $results);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Jobs;
|
|||||||
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Telemetry;
|
use FireflyIII\Models\Telemetry;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
@ -33,7 +34,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use JsonException;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SubmitTelemetryData
|
* Class SubmitTelemetryData
|
||||||
@ -61,7 +64,7 @@ class SubmitTelemetryData implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
@ -76,10 +79,19 @@ class SubmitTelemetryData implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$body = '[]';
|
||||||
$json = $this->parseJson($telemetry);
|
$json = $this->parseJson($telemetry);
|
||||||
|
try {
|
||||||
|
json_encode($json, JSON_THROW_ON_ERROR, 512);
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
Log::error('Could not parse JSON.');
|
||||||
|
throw new FireflyException(sprintf('Could not parse telemetry JSON: %s', $e->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client;
|
$client = new Client;
|
||||||
$options = [
|
$options = [
|
||||||
'body' => json_encode($json, JSON_THROW_ON_ERROR, 512),
|
'body' => $body,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
@ -89,11 +101,11 @@ class SubmitTelemetryData implements ShouldQueue
|
|||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$result = $client->post($url, $options);
|
$result = $client->post($url, $options);
|
||||||
} catch (GuzzleException $e) {
|
} catch (GuzzleException|Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
Log::error('Could not submit telemetry.');
|
Log::error('Could not submit telemetry.');
|
||||||
return;
|
throw new FireflyException(sprintf('Could not submit telemetry: %s', $e->getMessage()));
|
||||||
}
|
}
|
||||||
$body = (string) $result->getBody();
|
$body = (string) $result->getBody();
|
||||||
$statusCode = $result->getStatusCode();
|
$statusCode = $result->getStatusCode();
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Cronjobs;
|
namespace FireflyIII\Support\Cronjobs;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Jobs\SubmitTelemetryData;
|
use FireflyIII\Jobs\SubmitTelemetryData;
|
||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
use Log;
|
use Log;
|
||||||
@ -35,9 +36,17 @@ class TelemetryCronjob extends AbstractCronjob
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function fire(): bool
|
public function fire(): bool
|
||||||
{
|
{
|
||||||
|
// do not fire if telemetry is disabled.
|
||||||
|
if (false === config('firefly.send_telemetry') || false === config('firefly.feature_flags.telemetry')) {
|
||||||
|
Log::warning('Telemetry is disabled. The cron job will do nothing.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @var Configuration $config */
|
/** @var Configuration $config */
|
||||||
$config = app('fireflyconfig')->get('last_tm_job', 0);
|
$config = app('fireflyconfig')->get('last_tm_job', 0);
|
||||||
$lastTime = (int) $config->data;
|
$lastTime = (int) $config->data;
|
||||||
@ -46,8 +55,8 @@ class TelemetryCronjob extends AbstractCronjob
|
|||||||
if (0 === $lastTime) {
|
if (0 === $lastTime) {
|
||||||
Log::info('Telemetry cron-job has never fired before.');
|
Log::info('Telemetry cron-job has never fired before.');
|
||||||
}
|
}
|
||||||
// less than half a day ago:
|
// less than a week ago:
|
||||||
if ($lastTime > 0 && $diff <= 43200) {
|
if ($lastTime > 0 && $diff <= 604800) {
|
||||||
Log::info(sprintf('It has been %s since the telemetry cron-job has fired.', $diffForHumans));
|
Log::info(sprintf('It has been %s since the telemetry cron-job has fired.', $diffForHumans));
|
||||||
if (false === $this->force) {
|
if (false === $this->force) {
|
||||||
Log::info('The cron-job will not fire now.');
|
Log::info('The cron-job will not fire now.');
|
||||||
@ -60,8 +69,8 @@ class TelemetryCronjob extends AbstractCronjob
|
|||||||
Log::info('Execution of the telemetry cron-job has been FORCED.');
|
Log::info('Execution of the telemetry cron-job has been FORCED.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// more than a week ago.
|
||||||
if ($lastTime > 0 && $diff > 43200) {
|
if ($lastTime > 0 && $diff > 604799) {
|
||||||
Log::info(sprintf('It has been %s since the telemetry cron-job has fired. It will fire now!', $diffForHumans));
|
Log::info(sprintf('It has been %s since the telemetry cron-job has fired. It will fire now!', $diffForHumans));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +83,7 @@ class TelemetryCronjob extends AbstractCronjob
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
private function fireTelemetry(): void
|
private function fireTelemetry(): void
|
||||||
{
|
{
|
||||||
@ -87,4 +96,4 @@ class TelemetryCronjob extends AbstractCronjob
|
|||||||
app('fireflyconfig')->set('last_tm_job', (int) $this->date->format('U'));
|
app('fireflyconfig')->set('last_tm_job', (int) $this->date->format('U'));
|
||||||
Log::info('Done with telemetry cron job task.');
|
Log::info('Done with telemetry cron job task.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
|
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
|
||||||
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
||||||
|
use FireflyIII\Support\Cronjobs\TelemetryCronjob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait CronRunner
|
* Trait CronRunner
|
||||||
@ -51,6 +52,24 @@ trait CronRunner
|
|||||||
return 'The recurring transaction cron job fired successfully.';
|
return 'The recurring transaction cron job fired successfully.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function runTelemetry(): string {
|
||||||
|
/** @var TelemetryCronjob $telemetry */
|
||||||
|
$telemetry = app(TelemetryCronjob::class);
|
||||||
|
try {
|
||||||
|
$result = $telemetry->fire();
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
if (false === $result) {
|
||||||
|
return 'The telemetry cron job did not fire.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'The telemetry cron job fired successfully.';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -139,7 +139,7 @@ return [
|
|||||||
],
|
],
|
||||||
'feature_flags' => [
|
'feature_flags' => [
|
||||||
'export' => true,
|
'export' => true,
|
||||||
'telemetry' => false,
|
'telemetry' => true,
|
||||||
],
|
],
|
||||||
|
|
||||||
'encryption' => null === env('USE_ENCRYPTION') || true === env('USE_ENCRYPTION'),
|
'encryption' => null === env('USE_ENCRYPTION') || true === env('USE_ENCRYPTION'),
|
||||||
|
Loading…
Reference in New Issue
Block a user