From 536b38a27f5ca16e40eb3de4d1fd8e6f1d25e924 Mon Sep 17 00:00:00 2001 From: horus Date: Mon, 3 Jan 2022 14:55:31 +0100 Subject: Adding new users should be async. (Does not work yet.) --- app/Http/Controllers/IndexController.php | 41 +++++++++++++++++++- app/Jobs/AddNewCalUser.php | 66 ++++++++++++++++++++++++++++++++ app/Libraries/Helper.php | 2 + 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/AddNewCalUser.php (limited to 'app') diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index d9e792a..c595b4e 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -11,6 +11,9 @@ use App\AnimeStats; use App\MALUser; use App\Libraries\Helper; +use App\Jobs\AddNewCalUser; +use Imtigger\LaravelJobStatus\JobStatus; + class IndexController extends Controller { /** * Shows the index page. @@ -81,10 +84,12 @@ class IndexController extends Controller { echo "OK"; } - public function createUser( $username ) { + public function _createUser( $username ) { $helper = new Helper(); $helper->createUser( $username ); - $helper->setIsWatching( $username ); + if ( false === $helper->setIsWatching( $username ) ) { + echo "not ok"; return; + } $helper->setCalendar( $username ); echo "OK. https://animes.iamfabulous.de/ical/" . $username; return; @@ -103,4 +108,36 @@ class IndexController extends Controller { echo $user->get(); } + + public function createUser( $username ) { + + $job = new AddNewCalUser( $username ); + #$job = AddNewCalUser::create(); + $id = $job::dispatch( $username ); + + echo "
";
+		#var_dump($job->id);
+		var_dump($job);
+		var_dump($id);
+		#$jobStatusId = $job->getJobStatusId();
+		#echo "https://anistats.com/status/" . $jobStatusId;
+	}
+
+	public function showJobStatus( $jobStatusId ) {
+		$jobStatus = JobStatus::find($jobStatusId);
+
+		echo "
";
+		/*
+		while ( "queued" == $jobStatus->status || "executing" == $jobStatus->status ) {
+			echo $jobStatus->status;
+			echo "";
+			$jobStatus = JobStatus::find($jobStatusId);
+			sleep(1);
+		}
+		 */
+
+		var_dump($jobStatus);
+		var_dump($jobStatus->output);
+
+	}
 }
diff --git a/app/Jobs/AddNewCalUser.php b/app/Jobs/AddNewCalUser.php
new file mode 100644
index 0000000..dfb74fe
--- /dev/null
+++ b/app/Jobs/AddNewCalUser.php
@@ -0,0 +1,66 @@
+username = $username;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+	$helper = new Helper();
+	$helper->createUser( $this->username );
+	if ( false === $helper->setIsWatching( $this->username ) ) {
+		echo "fail!!!";
+		#$this->setOutput(["status" => "fail", "reason" => "user does not exist", "username" => $this->username]);
+		$this->queueData(["status" => "fail", "reason" => "user does not exist", "username" => $this->username]);
+
+	} else {
+		$helper->setCalendar( $this->username );
+		#$this->setOutput(["status" => "okay", "reason" => "", "username" => $this->username]);
+		$this->queueData(["status" => "okay", "reason" => "", "username" => $this->username]);
+	}
+
+		$this->fail();
+    }
+
+    /*
+    public function uniqueId() {
+	    #return $this->username;
+    }
+     */
+}
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php
index 71e3cea..4ab1e75 100644
--- a/app/Libraries/Helper.php
+++ b/app/Libraries/Helper.php
@@ -162,9 +162,11 @@ class Helper {
 		$actually_watching = array();
 
 		$anime = $user->getIsWatching();
+
 		if ( false === $anime )
 			return false;
 
+
 		foreach( $anime as $anime_details ) {
 			$check = DB::table('is_watching')
 				->where('mal_id', $anime_details["mal_id"])
-- 
cgit v1.2.3