Skip to content

Commit

Permalink
Only allow output string instead of exception when logging
Browse files Browse the repository at this point in the history
  • Loading branch information
David Vandemaele committed Mar 30, 2022
1 parent 98aa272 commit 09669de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
7 changes: 1 addition & 6 deletions lib/Skeleton/Transaction/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,14 @@ public static function get_last_successful() {
* Create log.
*/
public static function create(
\Transaction $transaction, bool $failed, string $output = '', ?\Throwable $t = null,
?string $date = null
\Transaction $transaction, bool $failed, string $output = '', ?string $date = null
): self {

$log = new self();
$log->transaction_id = $transaction->id;
$log->failed = $failed;
$log->output = $output;

if (isset($t) === true) {
$log->exception = print_r($t, true);
}

if ($date !== null) {
$log->created = (new \DateTime($date))->format('Y-m-d H:i:s');
}
Expand Down
16 changes: 6 additions & 10 deletions lib/Skeleton/Transaction/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ trait Retry {
* Retry transaction after a specified time (default: 15 minutes)
*
* @access public
* @param \Exception $exception
* @param string $output
* @param string $next_retry
*/
public function retry(\Exception $exception = null, $output = null, $next_retry = '+15 minutes') {
public function retry($output = null, $next_retry = '+15 minutes') {
if (self::$max_attempts > 0 && $this->retry_attempt >= self::$max_attempts) {
echo $output;
throw $exception;
throw new \Exception($output);
}

Log::create($this, true, $output, $exception);
Log::create($this, true, $output);

$this->retry_attempt++;
$this->schedule($next_retry);
Expand All @@ -43,18 +41,16 @@ public function retry(\Exception $exception = null, $output = null, $next_retry
* Retry transaction using an incremental time algorithm
*
* @access public
* @param \Exception $exception
* @param string $output
* @param int $exp
* @param string $unit
*/
public function retry_incremental(\Exception $exception = null, $output = null, $exp = 2, $unit = 'minutes') {
public function retry_incremental($output = null, $exp = 2, $unit = 'minutes') {
if (self::$max_attempts > 0 && $this->retry_attempt >= self::$max_attempts) {
echo $output;
throw $exception;
throw new \Exception($output);
}

Log::create($this, true, $output, $exception);
Log::create($this, true, $output);

$this->retry_attempt++;
$this->schedule(pow($this->retry_attempt, $exp) . ' ' . $unit);
Expand Down
6 changes: 3 additions & 3 deletions lib/Skeleton/Transaction/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function unlock() {
* @access public
*/
public function mark_failed($output, $exception, $date = null) {
Log::create($this, true, $output, $exception, $date);
Log::create($this, true, print_r($exception, true), $date);

$this->failed = true;
$this->completed = true;
Expand All @@ -229,8 +229,8 @@ public function mark_failed($output, $exception, $date = null) {
* @param string $date
*/
public function mark_completed($output, $date = null) {
Log::create($this, false, $output, null, $date);
Log::create($this, false, $output, $date);

// Don't mark this transaction as completed if it has been rescheduled.
if ($this->rescheduled) {
return;
Expand Down

0 comments on commit 09669de

Please sign in to comment.