Skip to content

Commit

Permalink
Add purge command
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Apr 25, 2021
1 parent 22bc2c1 commit 1f40a16
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Commands/PurgeAnalytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Turbo124\Beacon\Commands;

use App;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Turbo124\Beacon\Jobs\BatchMetrics;


class PurgeAnalytics extends Command
{
/**
* @var string
*/
protected $name = 'beacon:purge';

/**
* @var string
*/
protected $description = 'Purging any analytics in the cache';

protected $log = '';

public function handle()
{
$this->logMessage('Purging Data');

$metric_types = ['counter', 'gauge', 'multi_metric', 'mixed_metric'];

foreach($metric_types as $type)
{

$this->logMessage("purging {$type}");

Cache::forget(config('beacon.cache_key') . '_' . $type);
}

$this->logMessage('Finished Purging Data');


}

private function logMessage($str)
{
$str = date('Y-m-d h:i:s') . ' ' . $str;
$this->info($str);
$this->log .= $str . " \n";
}
}

0 comments on commit 1f40a16

Please sign in to comment.