Mwalker has uploaded a new change for review.
https://gerrit.wikimedia.org/r/63154
Change subject: Adding a global Context Class
......................................................................
Adding a global Context Class
This allows us to track things with yet another ID :)
Change-Id: I5a10496b35ba1f10b9d3a8fd91e8f678436aa350
---
A SmashPig/Core/Context.php
M SmashPig/Core/Http/RequestHandler.php
M SmashPig/Core/Listeners/RestListener.php
M SmashPig/Core/Listeners/SoapListener.php
M SmashPig/Maintenance/MaintenanceBase.php
M SmashPig/config_defaults.php
6 files changed, 67 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/PaymentsListeners
refs/changes/54/63154/1
diff --git a/SmashPig/Core/Context.php b/SmashPig/Core/Context.php
new file mode 100644
index 0000000..c525271
--- /dev/null
+++ b/SmashPig/Core/Context.php
@@ -0,0 +1,61 @@
+<?php
+namespace SmashPig\Core;
+
+/**
+ * Global context object -- useful for managing global variables when
+ * we don't actually want globals or dedicated static classes.
+ *
+ * @package SmashPig\Core
+ */
+class Context {
+ protected static $instance;
+
+ public static function init() {
+ if ( !Context::$instance ) {
+ Context::$instance = new Context();
+ }
+ }
+
+ /**
+ * Obtains the current context object
+ * @return Context
+ */
+ public static function get() {
+ if ( Context::$instance === null ) {
+ Context::init();
+ }
+ return Context::$instance;
+ }
+
+ /**
+ * Sets the current context, returning the displaced context
+ * @param Context $c
+ * @return Context
+ */
+ public static function set( Context $c = null ) {
+ $old = Context::$instance;
+ Context::$instance = ( $c === null ) ? new Context() : $c;
+
+ return $old;
+ }
+
+ protected $contextId;
+
+ public function __construct( $cid = null ) {
+ if ( !$cid ) {
+ $this->contextId = sprintf( 'SPCID-%010d', mt_rand(
10000, pow( 2, 31 ) - 1 ) );
+ } else {
+ $this->contextId = $cid;
+ }
+ }
+
+ /**
+ * Gets the global context identifier - this is used for logging,
filenames,
+ * or other identifiers specific to the current job.
+ *
+ * @return string Format of SPCID-[1-9][0-9]{8}
+ */
+ public function getContextId() {
+ return $this->contextId;
+ }
+}
\ No newline at end of file
diff --git a/SmashPig/Core/Http/RequestHandler.php
b/SmashPig/Core/Http/RequestHandler.php
index 0940976..ee2fa7a 100644
--- a/SmashPig/Core/Http/RequestHandler.php
+++ b/SmashPig/Core/Http/RequestHandler.php
@@ -1,6 +1,7 @@
<?php namespace SmashPig\Core\Http;
use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
use SmashPig\Core\Logging\Logger;
use SmashPig\Core\AutoLoader;
@@ -53,6 +54,8 @@
true
);
Logger::init( $config->val( 'logging/root-context' ),
$config->val( 'logging/log-level' ), $config );
+ Context::init();
+ Logger::enterContext( Context::get()->getContextId() );
set_error_handler(
'\SmashPig\Core\Http\RequestHandler::lastChanceErrorHandler' );
set_exception_handler(
'\SmashPig\Core\Http\RequestHandler::lastChanceExceptionHandler' );
diff --git a/SmashPig/Core/Listeners/RestListener.php
b/SmashPig/Core/Listeners/RestListener.php
index c0f224a..a5473ea 100644
--- a/SmashPig/Core/Listeners/RestListener.php
+++ b/SmashPig/Core/Listeners/RestListener.php
@@ -7,7 +7,6 @@
abstract class RestListener extends ListenerBase {
public function execute( Request $request, Response $response,
$pathParts ) {
- Logger::enterContext( 'sess' . mt_rand( 100000000, 999999999 )
);
Logger::info( "Starting processing of listener request from
{$_SERVER[ 'REMOTE_ADDR' ]}" );
try {
diff --git a/SmashPig/Core/Listeners/SoapListener.php
b/SmashPig/Core/Listeners/SoapListener.php
index 9278780..35b1f68 100644
--- a/SmashPig/Core/Listeners/SoapListener.php
+++ b/SmashPig/Core/Listeners/SoapListener.php
@@ -28,7 +28,6 @@
}
public function execute( Request $request, Response $response,
$pathParts ) {
- Logger::enterContext( 'sess' . mt_rand( 100000000, 999999999 )
);
Logger::info( "Starting processing of listener request from
{$_SERVER[ 'REMOTE_ADDR' ]}" );
try {
diff --git a/SmashPig/Maintenance/MaintenanceBase.php
b/SmashPig/Maintenance/MaintenanceBase.php
index 62ee997..0c89b18 100644
--- a/SmashPig/Maintenance/MaintenanceBase.php
+++ b/SmashPig/Maintenance/MaintenanceBase.php
@@ -9,6 +9,7 @@
use SmashPig\Core\AutoLoader;
use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
use SmashPig\Core\Logging\Logger;
use SmashPig\Core\Logging\ConsoleLogStream;
use SmashPig\Core\SmashPigException;
@@ -137,7 +138,7 @@
);
Logger::addLogStream( new ConsoleLogStream() );
- Logger::enterContext( "run" . mt_rand( 100000000, 999999999 ) );
+ Logger::enterContext( Context::get()->getContextId() );
set_error_handler(
'\SmashPig\Maintenance\MaintenanceBase::lastChanceErrorHandler' );
set_exception_handler(
'\SmashPig\Maintenance\MaintenanceBase::lastChanceExceptionHandler' );
diff --git a/SmashPig/config_defaults.php b/SmashPig/config_defaults.php
index 2f4ca44..bb5638f 100644
--- a/SmashPig/config_defaults.php
+++ b/SmashPig/config_defaults.php
@@ -26,7 +26,7 @@
// Library definitions
'stomp' => array(
- 'lib-path' =>
'/var/www/fr-payments/extensions/DonationInterface/activemq_stomp/Stomp.php',
+ 'lib-path' => '',
'uri' => 'tcp://localhost:61613',
'timeout' => 1,
--
To view, visit https://gerrit.wikimedia.org/r/63154
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a10496b35ba1f10b9d3a8fd91e8f678436aa350
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/PaymentsListeners
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits