summaryrefslogtreecommitdiff
path: root/app/Jobs/AddNewCalUser.php
blob: dfb74fec4da5adc15cc1c93de25ce7b77627f2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
    }
     */
}