Explorar el Código

added example batch job.

markus hace 1 mes
padre
commit
fdd6e8788c

+ 24 - 0
src-php/app/internship/batch/UpdateDateTimeInFile.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace internship\batch;
+
+use n2n\context\Lookupable;
+use n2n\batch\attribute\BatchInterval;
+
+class UpdateDateTimeInFile implements Lookupable {
+
+	public function _onTrigger() {
+		// gets called every time the batch job is triggered
+	}
+
+	public function _onNewHour() {
+		echo 'one hour passed';
+	}
+
+	#[BatchInterval(new \DateInterval('PT15M'))]
+	public function every15Min(): void {
+		// gets called every 15 minutes
+		file_put_contents('currentTimeSetByBatch.txt', date('d-m-Y-H-i-s'));
+		echo '15 minutes passed';
+	}
+}

+ 0 - 6
src-php/app/internship/bo/Order.php

@@ -5,12 +5,6 @@ namespace internship\bo;
 use n2n\reflection\ObjectAdapter;
 
 class Order extends ObjectAdapter implements \JsonSerializable {
-	/*private static function _annos(AnnoInit $ai) {
-		$ai->p('address', new AnnoEmbedded(Address::getClass()),
-				new AnnoAttributeOverrides(array('forename' => 'bill_forename',
-						'surname' => 'bill_surname')));
-		$ai->p('deliveryAddress', new AnnoEmbedded(Address::getClass(), 'delivery_'));
-	}*/
 
 	public int $id;
 	public string $productName;

+ 1 - 1
src-php/public/batch.php

@@ -10,7 +10,7 @@ if (isset($_SERVER['N2N_STAGE'])) {
 	define('N2N_STAGE', $_SERVER['N2N_STAGE']);
 }
 
-// require __DIR__ . '/../vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 require_once '../vendor/n2n/n2n/src/app/n2n/core/TypeLoader.php';
 
 n2n\core\TypeLoader::register(true,

+ 2 - 0
src-php/public/index.php

@@ -20,6 +20,8 @@ n2n\core\TypeLoader::register(true,
 
 n2n\core\N2N::initialize($pubPath, $varPath, new n2n\core\FileN2nCache());
 n2n\core\N2N::autoInvokeControllers();
+
+
 n2n\core\N2N::finalize();
 
 

+ 1 - 0
src-php/var/etc/app.ini

@@ -3,6 +3,7 @@ page.name = "New awesome project"
 
 application.name = "newAwesomeProject"
 
+application.batch_jobs[] = "internship\batch\UpdateDateTimeInFile"
 
 [web]
 response.browser_caching_enabled = true