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