get status from github api
This commit is contained in:
@@ -4,3 +4,5 @@ class GithubRun(models.Model):
|
||||
id = models.IntegerField(verbose_name="ID",primary_key=True)
|
||||
uuid = models.CharField(verbose_name="uuid", max_length=100)
|
||||
status = models.CharField(verbose_name="status", max_length=100)
|
||||
github_run_id = models.BigIntegerField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
80
rdgenerator/templates/failure.html
Normal file
80
rdgenerator/templates/failure.html
Normal file
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Generation Failed</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f9f9f9;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
max-width: 400px;
|
||||
}
|
||||
.icon {
|
||||
font-size: 48px;
|
||||
color: #d9534f;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
h1 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 24px;
|
||||
}
|
||||
p {
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.btn:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<div class="icon">✕</div>
|
||||
<h1>Generation Failed</h1>
|
||||
<p>Something went wrong during the GitHub Action process. This could be due to a timeout, a script error, or a server issue.</p>
|
||||
|
||||
<a href="/" class="btn">Return to Form</a>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="icon">✕</div>
|
||||
<h1>Generation Failed</h1>
|
||||
<p>Something went wrong during the process.</p>
|
||||
|
||||
<div style="background: #f1f1f1; padding: 15px; border-radius: 5px; margin-bottom: 20px;">
|
||||
<a href="{{ log_url }}" target="_blank" style="color: #d9534f; font-weight: bold;">
|
||||
Check GitHub Logs for Errors
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a href="/" class="btn">Return to Form</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -69,6 +69,28 @@
|
||||
background-color: #3498db;
|
||||
transition: width 0.5s ease-in-out;
|
||||
}
|
||||
.log-container {
|
||||
margin-top: 30px;
|
||||
padding: 15px;
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
border-radius: 12px;
|
||||
font-size: 0.85em;
|
||||
max-width: 320px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border: 1px solid rgba(0,0,0,0.05);
|
||||
}
|
||||
.log-link {
|
||||
color: #3498db;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.log-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -140,8 +162,16 @@
|
||||
<div class="progress-bar">
|
||||
<div id="progressBarFill" class="progress-bar-fill"></div>
|
||||
</div>
|
||||
<p class="status-text">This can take 20-30 minutes (or longer if there are other users).</p>
|
||||
<p class="status-text">This can take 30-45 minutes. You can leave this page open or come back later.</p>
|
||||
<p class="status-text">Status: <span id="statusText">{{status}}</span></p>
|
||||
|
||||
<div class="log-container">
|
||||
<p style="margin: 0 0 8px 0; color: #888;">Technical View</p>
|
||||
<a href="{{ log_url }}" target="_blank" class="log-link">
|
||||
View GitHub Action Logs
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="macosNote" class="macos-note">
|
||||
@@ -212,7 +242,7 @@
|
||||
|
||||
setTimeout(function() {
|
||||
window.location.replace('/check_for_file?filename={{filename}}&uuid={{uuid}}&platform={{platform}}');
|
||||
}, 20000); // 20000 milliseconds = 20 seconds
|
||||
}, 30000); // 20000 milliseconds = 20 seconds
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -302,7 +302,8 @@ def generator_view(request):
|
||||
"inputs":{
|
||||
"version":version,
|
||||
"zip_url":zip_url
|
||||
}
|
||||
},
|
||||
"return_run_details": True
|
||||
}
|
||||
#print(data)
|
||||
headers = {
|
||||
@@ -311,13 +312,26 @@ def generator_view(request):
|
||||
'Authorization': 'Bearer '+_settings.GHBEARER,
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
create_github_run(myuuid)
|
||||
response = requests.post(url, json=data, headers=headers)
|
||||
print(response)
|
||||
if response.status_code == 204 or response.status_code == 200:
|
||||
return render(request, 'waiting.html', {'filename':filename, 'uuid':myuuid, 'status':"Starting generator...please wait", 'platform':platform})
|
||||
else:
|
||||
return JsonResponse({"error": "Something went wrong"})
|
||||
new_github_run = GithubRun(
|
||||
uuid=myuuid,
|
||||
status="Starting generator...please wait"
|
||||
)
|
||||
try:
|
||||
response = requests.post(url, json=data, headers=headers)
|
||||
#print(response)
|
||||
if response.status_code == 204 or response.status_code == 200:
|
||||
github_data = response.json()
|
||||
new_github_run.github_run_id = github_data.get('id')
|
||||
new_github_run.status = "in_progress"
|
||||
new_github_run.save()
|
||||
|
||||
return render(request, 'waiting.html', {'filename':filename, 'uuid':myuuid, 'status':"Starting generator...please wait", 'platform':platform})
|
||||
else:
|
||||
new_github_run.delete()
|
||||
return JsonResponse({"error": "GitHub rejected the start request"}, status=500)
|
||||
except Exception as e:
|
||||
new_github_run.delete()
|
||||
return JsonResponse({"error": f"Connection error: {str(e)}"}, status=500)
|
||||
else:
|
||||
form = GenerateForm()
|
||||
#return render(request, 'maintenance.html')
|
||||
@@ -330,12 +344,31 @@ def check_for_file(request):
|
||||
platform = request.GET['platform']
|
||||
gh_run = GithubRun.objects.filter(Q(uuid=uuid)).first()
|
||||
status = gh_run.status
|
||||
if status not in ['success', 'failure', 'cancelled']:
|
||||
headers = {"Authorization": f"Bearer {_settings.GHBEARER}"}
|
||||
api_url = f"https://api.github.com/repos/{_settings.GHUSER}/{_settings.REPONAME}/actions/runs/{gh_run.github_run_id}"
|
||||
github_log_url = f"https://github.com/{_settings.GHUSER}/{_settings.REPONAME}/actions/runs/{gh_run.github_run_id}"
|
||||
|
||||
timeout_limit = gh_run.created_at + timedelta(hours=2)
|
||||
|
||||
try:
|
||||
gh_response = requests.get(api_url, headers=headers)
|
||||
if gh_response.status_code == 200:
|
||||
gh_data = gh_response.json()
|
||||
|
||||
if gh_data['status'] == 'completed':
|
||||
gh_run.status = gh_data['conclusion'] # 'success' or 'failure'
|
||||
gh_run.save()
|
||||
except Exception as e:
|
||||
print(f"Error checking GitHub: {e}")
|
||||
|
||||
#if file_exists:
|
||||
if status == "Success":
|
||||
if gh_run.status == "success":
|
||||
return render(request, 'generated.html', {'filename': filename, 'uuid':uuid, 'platform':platform})
|
||||
elif gh_run.status == "failure":
|
||||
return render(request, 'failure.html', {'log_url': github_log_url})
|
||||
else:
|
||||
return render(request, 'waiting.html', {'filename':filename, 'uuid':uuid, 'status':status, 'platform':platform})
|
||||
return render(request, 'waiting.html', {'filename':filename, 'uuid':uuid, 'status':status, 'platform':platform, 'log_url': github_log_url})
|
||||
|
||||
def download(request):
|
||||
filename = request.GET['filename']
|
||||
@@ -363,13 +396,6 @@ def get_png(request):
|
||||
|
||||
return response
|
||||
|
||||
def create_github_run(myuuid):
|
||||
new_github_run = GithubRun(
|
||||
uuid=myuuid,
|
||||
status="Starting generator...please wait"
|
||||
)
|
||||
new_github_run.save()
|
||||
|
||||
def update_github_run(request):
|
||||
data = json.loads(request.body)
|
||||
myuuid = data.get('uuid')
|
||||
|
||||
Reference in New Issue
Block a user