-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.sh
70 lines (54 loc) · 1.83 KB
/
job.sh
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
67
68
69
70
#!/bin/bash
echo "JOB.SH"
echo "===================================="
echo "Script will create a test job to test your queue"
echo "===================================="
sleep 5
# Define the path where the job class should be created
JOB_FILE_PATH="app/Jobs/TestQueueJob.php"
# Create the directory if it doesn't exist
mkdir -p "$(dirname "$JOB_FILE_PATH")"
# Create the job class file
cat <<EOL > $JOB_FILE_PATH
<?php
/**
* TestQueueJob.php
* Laravel job that logs its processing to a file.
*
* @package Digital Creativity Co
* @author George Awad <apps@@el-abda3.com>
* @copyright Copyright (c) 2024 Digital Creativity Co
* @license MIT
* @link https://el-abda3.com
* Mobile Applications Leaders [Let's work together]
*/
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\File;
class TestQueueJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public \$jobId;
public function __construct()
{
// Generate a unique ID for this job
\$this->jobId = uniqid('test:', true);
}
public function handle()
{
// Log when the job is processed
Log::info("TestQueueJob processed with ID: {\$this->jobId}");
// Write to a custom file to confirm the job was processed
File::append(storage_path('logs/job_processed.log'), "Job processed with ID: {\$this->jobId}\n");
// You could also directly echo to terminal if running synchronously
echo "Job processed with ID: {\$this->jobId}\n";
}
}
EOL
# Confirm the file creation
echo "Job class created at $JOB_FILE_PATH"