Skip to content

Commit

Permalink
Upd. Firewall Update. Update log extended.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergull committed May 16, 2024
1 parent 04c719b commit 42f3cfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions inc/fw-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function spbc_security_firewall_update__worker($checker_work = null)
Request::equal('updating_id', '')
|| ! Request::equal('updating_id', $spbc->fw_stats['updating_id'])
) {
spbc_security_firewall_update_log('FW UPDATE WORKER: WRONG_UPDATE_ID');
return array( 'error' => 'FW UPDATE WORKER: WRONG_UPDATE_ID' );
}
}
Expand All @@ -128,6 +129,7 @@ function spbc_security_firewall_update__worker($checker_work = null)
if ( $spbc->fw_stats['calls'] > 600 ) {
$spbc->error_add('firewall_update', 'WORKER_CALL_LIMIT_EXCEEDED');
$spbc->save('errors');
spbc_security_firewall_update_log('WORKER_CALL_LIMIT_EXCEEDED');
return array( 'error' => 'WORKER_CALL_LIMIT_EXCEEDED' );
}

Expand All @@ -138,8 +140,12 @@ function spbc_security_firewall_update__worker($checker_work = null)
return true;
}

spbc_security_firewall_update_log('Queue stage started ' . var_export($queue->getQueue(), true));

$result = $queue->executeStage();

spbc_security_firewall_update_log('Current stage result ' . var_export($result, true));

if ( $result === null ) {
// The stage is in progress, will try to wait up to 5 seconds to its complete
for ( $i = 0; $i < 5; $i++ ) {
Expand Down
16 changes: 14 additions & 2 deletions lib/CleantalkSP/Common/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,22 @@ public function executeStage()

if ($stage_to_execute) {
if (is_callable($stage_to_execute['name'])) {
spbc_security_firewall_update_log('Is callable:' . var_export($stage_to_execute['name'], true));

++$stage_to_execute['tries'];

if (! empty($stage_to_execute['args'])) {
$result = $stage_to_execute['name']($stage_to_execute['args']);
spbc_security_firewall_update_log('Executed stage: ' . var_export($stage_to_execute['name'], true) . ' with args ' . var_export($stage_to_execute['args'], true));
} else {
$result = $stage_to_execute['name']();
spbc_security_firewall_update_log('Executed stage: ' . var_export($stage_to_execute['name'], true) . ' with no args');
}

spbc_security_firewall_update_log('Stage result ' . var_export($result, true));

if (isset($result['error'])) {
spbc_security_firewall_update_log('Stage error ' . var_export($result['error'], true));
$stage_to_execute['status'] = 'NULL';
$stage_to_execute['error'][] = $result['error'];
if (isset($result['update_args']['args'])) {
Expand All @@ -148,18 +155,23 @@ public function executeStage()
if ($stage_to_execute['tries'] >= $accepted_tries) {
$stage_to_execute['status'] = 'FINISHED';
$this->saveQueue();

return $result;
}

return \CleantalkSP\SpbctWP\RemoteCalls::performToHost(
spbc_security_firewall_update_log('Stage has errors, proceed to RC ' . var_export($this->rc_name, true));

$rc_result = \CleantalkSP\SpbctWP\RemoteCalls::performToHost(
$this->rc_name,
array(
'updating_id' => $spbc->fw_stats['updating_id'],
'stage' => 'Repeat ' . $stage_to_execute['name']
),
array('async')
);

spbc_security_firewall_update_log('Stage RC result' . var_export($rc_result, true));

return $rc_result;
}

if (isset($result['next_stage'])) {
Expand Down

0 comments on commit 42f3cfc

Please sign in to comment.