summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2022-01-03 14:55:31 +0100
committerhorus2022-01-03 14:55:31 +0100
commit536b38a27f5ca16e40eb3de4d1fd8e6f1d25e924 (patch)
treeb1e67af2ec1ce94b492832af06cf995b9297d21d
parent6531270e480bd39cb1b364d8d1a3cd8a4fe3fc17 (diff)
downloadsenpai-536b38a27f5ca16e40eb3de4d1fd8e6f1d25e924.tar.gz
Adding new users should be async. (Does not work yet.)
-rw-r--r--app/Http/Controllers/IndexController.php41
-rw-r--r--app/Jobs/AddNewCalUser.php66
-rw-r--r--app/Libraries/Helper.php2
3 files changed, 107 insertions, 2 deletions
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 "<pre>";
+ #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 "<pre>";
+ /*
+ 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 @@
+<?php
+
+# TODO Implement ShouldBeUnique after upgrading to Laravel 8.x
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+#use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+
+use romanzipp\QueueMonitor\Traits\IsMonitored;
+
+use App\MALUser;
+use App\Libraries\Helper;
+
+#class AddNewCalUser implements ShouldQueue, ShouldBeUnique
+class AddNewCalUser implements ShouldQueue
+{
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, IsMonitored;
+
+ protected $username;
+
+ public $tries = 1;
+
+ /**
+ * Create a new job instance.
+ *
+ * @return void
+ */
+ public function __construct($username)
+ {
+ $this->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"])