-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sh
More file actions
78 lines (53 loc) · 2.2 KB
/
commands.sh
File metadata and controls
78 lines (53 loc) · 2.2 KB
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
71
72
73
74
75
76
77
78
#!/bin/bash
# Lab 09 - Job Registry with PostgreSQL
# Commands executed during the lab
# 1. Update system packages
sudo apt update
# 2. Install PostgreSQL
sudo apt install -y postgresql postgresql-contrib
# 3. Install Python and dependencies
sudo apt install -y python3 python3-pip python3-venv
# 3. Install Python and dependencies
python3 -m venv venv
# 3. Install Python and dependencies
source venv/bin/activate
pip install psycopg2-binary
# 4. Start PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql
# 5. Configure PostgreSQL access
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'labpassword';"
# 5. Configure PostgreSQL access
sudo -u postgres psql -c "CREATE DATABASE job_registry;"
# Step 1: Create Database Schema
nano schema.sql
# Step 2: Apply Schema
sudo -u postgres psql -d job_registry -f schema.sql
# Step 3: Verify Schema Creation
sudo -u postgres psql -d job_registry -c "\d jobs"
# Step 1: Create Job Manager Class
nano job_manager.py
# Step 2: Create Test Script
nano test_job_registry.py
# Step 3: Implement and Test
chmod +x test_job_registry.py
# Step 3: Implement and Test
python3 test_job_registry.py
# Verify Job Creation and Status Updates
sudo -u postgres psql -d job_registry -c "SELECT job_id, job_name, status, created_at FROM jobs ORDER BY job_id;"
# Verify Timestamps
sudo -u postgres psql -d job_registry -c "SELECT job_id, job_name, started_at, completed_at, (completed_at - started_at) AS duration FROM jobs WHERE status IN ('completed', 'failed');"
# Verify Results Storage
sudo -u postgres psql -d job_registry -c "SELECT job_id, job_name, result_data FROM jobs WHERE status = 'completed';"
# Verify Error Handling
sudo -u postgres psql -d job_registry -c "SELECT job_id, job_name, error_message FROM jobs WHERE status = 'failed';"
# Connection refused error
sudo systemctl status postgresql
# Connection refused error
sudo systemctl restart postgresql
# Module not found (`psycopg2`)
pip3 install --user psycopg2-binary
# Permission denied on database
sudo -u postgres psql -d job_registry -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;"
# Check existing jobs
sudo -u postgres psql -d job_registry -c "SELECT COUNT(*) FROM jobs;"