/** * Do the actual work of the script. */ public function execute() { $this->datastore = BaseQueueConsumer::getQueue($this->getOption('queue')); $startTime = time(); $messageCount = 0; // Open the file for read $infile = $this->getArgument('file'); $f = fopen($infile, 'r'); if (!$f) { $this->error("Could not open {$infile} for read", true); } // Do the loop! while (($line = fgets($f)) !== false) { if (substr($line, 0, 4) === 'raw=') { $message = $this->decodeLegacyMessage($line); } else { $message = json_decode($line, true); } if ($message === null) { Logger::error("Invalid line: {$line}"); continue; } $this->datastore->push($message); $messageCount++; if ($messageCount % 1000 == 0) { print '.'; } } print '\\n'; $elapsedTime = time() - $startTime; Logger::info("Imported {$messageCount} messages from {$infile} in {$elapsedTime} seconds."); }
public function setUp() { parent::setUp(); $this->config = AdyenTestConfiguration::createWithSuccessfulApi(); Context::initWithLogger($this->config); $this->jobQueue = BaseQueueConsumer::getQueue('jobs-adyen'); $this->jobQueue->createTable('jobs-adyen'); }
public function setUp() { parent::setUp(); Context::initWithLogger(QueueTestConfiguration::instance()); $this->queue = BaseQueueConsumer::getQueue('test'); $this->queue->createTable('test'); $damagedDb = DamagedDatabase::get(); $damagedDb->createTable(); $this->damaged = $damagedDb->getDatabase(); }
public function setUp() { parent::setUp(); $this->config = AdyenTestConfiguration::createWithSuccessfulApi(); Context::initWithLogger($this->config); $this->pendingDatabase = PendingDatabase::get(); $this->pendingMessage = json_decode(file_get_contents(__DIR__ . '/../Data/pending.json'), true); $this->pendingDatabase->storeMessage($this->pendingMessage); $this->antifraudQueue = BaseQueueConsumer::getQueue('payments-antifraud'); }
/** * Will run all the actions that are loaded (from the 'actions' configuration * node) and that are applicable to this message type. Will return true * if all actions returned true. Otherwise will return false. This implicitly * means that the message will be re-queued if any action fails. Therefore * all actions need to be idempotent. * * @returns bool True if all actions were successful. False otherwise. */ public function runActionChain() { Logger::info("Received new report from Adyen: {$this->pspReference}. Generated: {$this->eventDate}.", $this->reason); $jobQueue = BaseQueueConsumer::getQueue('jobs-adyen'); if (strpos($this->pspReference, 'settlement_detail_report') === 0) { $jobObject = DownloadReportJob::factory($this->merchantAccountCode, $this->reason); // FIXME: write queue wrapper to do these next two steps SourceFields::addToMessage($jobObject); $jobArray = json_decode($jobObject->toJson(), true); $jobQueue->push($jobArray); } else { // We don't know how to handle this report yet Logger::notice("Do not know how to handle report with name '{$this->pspReference}'"); } return parent::runActionChain(); }
public function testRecordCapture() { $verifiedQueue = BaseQueueConsumer::getQueue('verified'); $verifiedQueue->createTable('verified'); $capture = KeyedOpaqueStorableObject::fromJsonProxy('SmashPig\\PaymentProviders\\Adyen\\ExpatriatedMessages\\Capture', file_get_contents(__DIR__ . '/../Data/capture.json')); $job = RecordCaptureJob::factory($capture); $this->assertTrue($job->execute()); $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId('adyen', $capture->merchantReference); $this->assertNull($donorData, 'RecordCaptureJob left donor data on pending queue'); $verifiedMessage = $verifiedQueue->pop(); $this->assertNotNull($verifiedMessage, 'RecordCaptureJob did not send verified message'); // can we use arraySubset yet? $sameKeys = array_intersect(array_keys($verifiedMessage), array_keys($this->pendingMessage)); foreach ($sameKeys as $key) { if ($key === 'gateway_txn_id') { $this->assertEquals($capture->originalReference, $verifiedMessage[$key], 'RecordCaptureJob should have set gateway_txn_id'); } else { $this->assertEquals($this->pendingMessage[$key], $verifiedMessage[$key], "Value of key {$key} mutated"); } } }
/** * Do the actual work of the script. */ public function execute() { $this->damagedDatabase = DamagedDatabase::get(); $messages = $this->damagedDatabase->fetchRetryMessages($this->getOption('max-messages')); $stats = array(); $config = Configuration::getDefaultConfig(); foreach ($messages as $message) { $queueName = $message['original_queue']; // FIXME: getting it by alias, this will be annoying cos -new $queue = BaseQueueConsumer::getQueue($queueName); unset($message['original_queue']); $queue->push($message); $this->damagedDatabase->deleteMessage($message); if (isset($stats[$queueName])) { $stats[$queueName]++; } else { $stats[$queueName] = 1; } } foreach ($stats as $queueName => $count) { Logger::info("Requeued {$count} messages to {$queueName}."); } }