Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --heartbeat-interval option to artisan command #47

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}