Skip to content

Commit

Permalink
Added --heartbeat-interval option. Fixes botman/driver-slack/botman#13
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpigott committed May 23, 2019
1 parent a832671 commit 5f8079c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Commands/SlackRTMListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SlackRTMListenCommand extends Command
*
* @var string
*/
protected $signature = 'botman:listen-on-slack';
protected $signature = 'botman:listen-on-slack
{--heartbeat-interval=120 : Seconds to wait before checking the connection. Set to 0 to disable}';

/**
* The console command description.
Expand All @@ -27,8 +28,6 @@ class SlackRTMListenCommand extends Command

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Expand All @@ -46,6 +45,18 @@ public function handle()
require base_path('routes/botman.php');
}

//If a heartbeat is set, add a periodic timer to check the connection to the server
if ($this->option('heartbeat-interval') > 0) {
$checkConnection = function () {
$botman = resolve('botman');
$botman->getDriver()->getClient()->checkConnection();
};
$loop->addPeriodicTimer(
$this->option('heartbeat-interval'),
$checkConnection
);
}

$loop->run();
}
}

0 comments on commit 5f8079c

Please sign in to comment.