Skip to content

Commit

Permalink
Improve logs, error handling, debug & env usage, refacto curl
Browse files Browse the repository at this point in the history
  • Loading branch information
Slivo-fr committed May 9, 2019
1 parent ba1920e commit a0c6d88
Show file tree
Hide file tree
Showing 15 changed files with 878 additions and 258 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea/
/vendor/
logs/*
vendor/*
var/*
15 changes: 10 additions & 5 deletions Settings.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace Killbot;

class Settings
{

/*******************************************************************************************************************
* Basic configuration
* Should be enough to get your bot running.
* Dont forget to setup a cron job executing cron.php every $MAX_RUN_TIME + a small offset
* Dont forget to setup a cron job executing cron.php every $MAX_RUN_TIME + a small safety offset
* Running each 5 minutes should be fine with the default $MAX_RUN_TIME
******************************************************************************************************************/

// Entity ids you want to display killmails for.
Expand Down Expand Up @@ -69,8 +68,14 @@ class Settings
// Enable debugging behaviors
public static $DEBUG = false;

// Folder name for json logs
public static $KILL_LOG_FOLDER = 'logs';
// Define running environment, use 'DEV' or 'PROD'
public static $ENV = 'PROD';

// Logs path
public static $LOG_PATH = 'var/logs/';

// Pending kills path
public static $UNPROCESSED_PATH = 'var/pending/';

// ESI base URL
public static $ESI_URL = 'https://esi.evetech.net/';
Expand Down
33 changes: 33 additions & 0 deletions bin/cron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../Settings.php');

use Killbot\AlertHandler;
use Killbot\Killbot;
use Killbot\Logger;

set_error_handler(
function ($code, $message, $file, $line) {
throw new ErrorException($message, 0, $code, $file, $line);
}
);

set_exception_handler(
function ($exception) {
Logger::log($exception->getMessage());
if (Settings::$ENV === 'PROD' && Settings::$SEND_MAIL) {
AlertHandler::sendAlertMail($exception->getMessage(), $exception->getFile(), $exception->getLine());
} elseif (Settings::$ENV === 'DEV') {
throw $exception;
}
}
);

function runBot()
{
$killbot = new Killbot();
$killbot->run();
}

runBot();
8 changes: 8 additions & 0 deletions bin/mailcheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require_once('vendor/autoload.php');

use Killbot\AlertHandler;

AlertHandler::sendAlertMail('This is a test error message', __FILE__, __LINE__);

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"swiftmailer/swiftmailer": "^6.0",
"twig/twig": "^2.0",
"ext-json": "*",
"ext-curl": "*"
"ext-curl": "*",
"ramsey/uuid": "^3.8"
},
"autoload": {
"psr-4": {
"Killbot\\":""
"Killbot\\":"src/"
}
}
}
Loading

0 comments on commit a0c6d88

Please sign in to comment.