Skip to content

Commit f8b00e0

Browse files
committed
chg: [forum] show currently crawling accounts tasks
1 parent cac1300 commit f8b00e0

3 files changed

Lines changed: 78 additions & 29 deletions

File tree

var/www/blueprints/forums_explorer.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_json_response(data, status_code):
3535

3636
# ============= ROUTES ==============
3737

38-
@forums_explorer.route("/chats/explorer/forums", methods=['GET'])
38+
@forums_explorer.route("/forums/explorer", methods=['GET'])
3939
@login_required
4040
@login_read_only
4141
def forum_explorer_forums():
@@ -48,10 +48,10 @@ def forum_explorer_forums():
4848
return render_template('forums_explorer_forum.html', meta=meta[0], bootstrap_label=bootstrap_label)
4949

5050
forums = forums_viewer.get_forums()
51-
return render_template('forums_explorer_index.html', forums=forums, bootstrap_label=bootstrap_label, is_admin=current_user.is_in_role('admin'))
51+
return render_template('forums_explorer_index.html', forums=forums, bootstrap_label=bootstrap_label, is_admin=current_user.is_admin())
5252

5353

54-
@forums_explorer.route("/chats/explorer/forums/create", methods=['POST'])
54+
@forums_explorer.route("/forums/explorer/create", methods=['POST'])
5555
@login_required
5656
@login_admin
5757
def forum_explorer_forum_create():
@@ -61,7 +61,7 @@ def forum_explorer_forum_create():
6161
return redirect(url_for('forums_explorer.forum_explorer_crawler_manage', id=res[0]['id']))
6262

6363

64-
@forums_explorer.route("/chats/explorer/forums/crawler", methods=['GET'])
64+
@forums_explorer.route("/forums/explorer/crawler", methods=['GET'])
6565
@login_required
6666
@login_admin
6767
def forum_explorer_crawler_status():
@@ -76,7 +76,7 @@ def forum_explorer_crawler_status():
7676
return render_template('forums_explorer_crawler_index.html', forums=forums, bootstrap_label=bootstrap_label)
7777

7878

79-
@forums_explorer.route("/chats/explorer/forums/crawler/queue", methods=['GET'])
79+
@forums_explorer.route("/forums/explorer/crawler/queue", methods=['GET'])
8080
@login_required
8181
@login_admin
8282
def forum_explorer_crawler_queue():
@@ -89,7 +89,7 @@ def forum_explorer_crawler_queue():
8989

9090

9191

92-
@forums_explorer.route("/chats/explorer/forums/crawler/queue/enqueue", methods=['POST'])
92+
@forums_explorer.route("/forums/explorer/crawler/queue/enqueue", methods=['POST'])
9393
@login_required
9494
@login_admin
9595
def forum_explorer_crawler_queue_enqueue():
@@ -101,7 +101,7 @@ def forum_explorer_crawler_queue_enqueue():
101101
success = f"Queued Forum URL for crawl: {res[0].get('url')}"
102102
return redirect(url_for('forums_explorer.forum_explorer_crawler_queue', id=forum_id, success=success))
103103

104-
@forums_explorer.route("/chats/explorer/forums/crawler/queue/purge", methods=['POST'])
104+
@forums_explorer.route("/forums/explorer/crawler/queue/purge", methods=['POST'])
105105
@login_required
106106
@login_admin
107107
def forum_explorer_crawler_queue_purge():
@@ -115,7 +115,7 @@ def forum_explorer_crawler_queue_purge():
115115
return redirect(url_for('forums_explorer.forum_explorer_crawler_queue', id=forum_id, success=success))
116116

117117

118-
@forums_explorer.route("/chats/explorer/forums/crawler/manage", methods=['GET'])
118+
@forums_explorer.route("/forums/explorer/crawler/manage", methods=['GET'])
119119
@login_required
120120
@login_admin
121121
def forum_explorer_crawler_manage():
@@ -126,7 +126,7 @@ def forum_explorer_crawler_manage():
126126
return render_template('forums_explorer_crawler_manage.html', meta=meta[0], bootstrap_label=bootstrap_label)
127127

128128

129-
@forums_explorer.route("/chats/explorer/forums/crawler/config/edit", methods=['POST'])
129+
@forums_explorer.route("/forums/explorer/crawler/config/edit", methods=['POST'])
130130
@login_required
131131
@login_admin
132132
def forum_explorer_crawler_config_edit():
@@ -137,7 +137,7 @@ def forum_explorer_crawler_config_edit():
137137
return redirect(url_for('forums_explorer.forum_explorer_crawler_manage', id=forum_id))
138138

139139

140-
@forums_explorer.route("/chats/explorer/forums/crawler/account/save", methods=['POST'])
140+
@forums_explorer.route("/forums/explorer/crawler/account/save", methods=['POST'])
141141
@login_required
142142
@login_admin
143143
def forum_explorer_crawler_account_save():
@@ -150,7 +150,7 @@ def forum_explorer_crawler_account_save():
150150

151151

152152

153-
@forums_explorer.route("/chats/explorer/forums/crawler/account/reactivate", methods=['POST'])
153+
@forums_explorer.route("/forums/explorer/crawler/account/reactivate", methods=['POST'])
154154
@login_required
155155
@login_admin
156156
def forum_explorer_crawler_account_reactivate():
@@ -166,7 +166,7 @@ def forum_explorer_crawler_account_reactivate():
166166
return redirect(url_for(target, id=forum_id, success=success))
167167

168168

169-
@forums_explorer.route("/chats/explorer/forums/crawler/account/inflight/purge", methods=['POST'])
169+
@forums_explorer.route("/forums/explorer/crawler/account/inflight/purge", methods=['POST'])
170170
@login_required
171171
@login_admin
172172
def forum_explorer_crawler_account_inflight_purge():
@@ -180,7 +180,7 @@ def forum_explorer_crawler_account_inflight_purge():
180180
return redirect(url_for('forums_explorer.forum_explorer_crawler_manage', id=forum_id, success=success))
181181

182182

183-
@forums_explorer.route("/chats/explorer/forums/crawler/account/inflight/resend", methods=['POST'])
183+
@forums_explorer.route("/forums/explorer/crawler/account/inflight/resend", methods=['POST'])
184184
@login_required
185185
@login_admin
186186
def forum_explorer_crawler_account_inflight_resend():
@@ -193,7 +193,7 @@ def forum_explorer_crawler_account_inflight_resend():
193193
success = f"Resent current inflight crawl for account {account_id}"
194194
return redirect(url_for('forums_explorer.forum_explorer_crawler_manage', id=forum_id, success=success))
195195

196-
@forums_explorer.route("/chats/explorer/forums/crawler/account/delete", methods=['POST'])
196+
@forums_explorer.route("/forums/explorer/crawler/account/delete", methods=['POST'])
197197
@login_required
198198
@login_admin
199199
def forum_explorer_crawler_account_delete():
@@ -262,7 +262,7 @@ def forum_explorer_subforum():
262262
return render_template('forums_explorer_subforum.html', meta=meta[0], bootstrap_label=bootstrap_label)
263263

264264

265-
@forums_explorer.route("/chats/explorer/forums/thread", methods=['GET'])
265+
@forums_explorer.route("/forums/explorer/thread", methods=['GET'])
266266
@login_required
267267
@login_read_only
268268
def forum_explorer_thread():

var/www/templates/forums_explorer/forums_explorer_crawler_index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
.forum-row:hover { background: #f6f9fb; text-decoration: none; color: inherit; }
1717
.forum-icon { width: 48px; height: 48px; border-radius: 50%; background: #d9edf7; color: #2f6f8f; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; margin-right: 1rem; flex: 0 0 48px; }
1818
.forum-stats { min-width: 440px; text-align: right; color: #6c757d; }
19+
.table-status-wrapper { overflow-x: auto; }
20+
.text-break { word-break: break-word; }
1921
</style>
2022
</head>
2123
<body>
@@ -36,6 +38,46 @@ <h1 class="mb-1"><i class="fas fa-spider"></i> Forum crawler status</h1>
3638
<p class="mb-0">Read-only status for configured Forum crawlers.</p>
3739
</div>
3840

41+
42+
<h5 class="mt-3 mb-2"><i class="fas fa-running"></i> Currently crawling forum accounts</h5>
43+
<div class="forum-board mb-4">
44+
{% set has_running = namespace(value=false) %}
45+
<div class="table-status-wrapper">
46+
<table class="table table-sm table-hover mb-0">
47+
<thead>
48+
<tr>
49+
<th>Forum</th>
50+
<th>Account</th>
51+
<th>Launch time</th>
52+
<th>Status</th>
53+
<th>Task UUID</th>
54+
<th>Current URL</th>
55+
<th>Stale</th>
56+
</tr>
57+
</thead>
58+
<tbody>
59+
{% for forum in forums %}
60+
{% for account in forum['crawler_status'].get('running', []) %}
61+
{% set has_running.value = true %}
62+
<tr>
63+
<td><a href="{{ url_for('forums_explorer.forum_explorer_crawler_status') }}?id={{ forum['id'] }}">{{ forum.get('name') or forum['id'] }}</a></td>
64+
<td>{{ account.get('account_id') }}</td>
65+
<td>{{ account.get('launch_time') }}</td>
66+
<td><span class="badge badge-success">{{ account.get('status') }}</span></td>
67+
<td class="text-break">{{ account.get('current_task_uuid') }}</td>
68+
<td class="text-break">{{ account.get('current_url') }}</td>
69+
<td>{% if account.get('stale') %}<span class="badge badge-warning">stale</span> {{ account.get('stale_reasons')|join(', ') }}{% else %}<span class="text-success">False</span>{% endif %}</td>
70+
</tr>
71+
{% endfor %}
72+
{% endfor %}
73+
{% if not has_running.value %}
74+
<tr><td colspan="7" class="text-muted text-center py-3">No forum accounts are currently crawling.</td></tr>
75+
{% endif %}
76+
</tbody>
77+
</table>
78+
</div>
79+
</div>
80+
3981
{% if forums %}
4082
<div class="forum-board mb-4">
4183
<div class="forum-board-header">Forums</div>

var/www/templates/forums_explorer/forums_explorer_index.html

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,27 @@ <h1 class="mb-1"><i class="fas fa-comments"></i> Forums Explorer</h1>
3030
<a class="btn btn-sm btn-outline-light mt-3" href="{{ url_for('forums_explorer.forum_explorer_crawler_status') }}"><i class="fas fa-spider"></i> Forum crawler status</a>
3131
</div>
3232

33-
{% if is_admin %}
34-
<div class="forum-board mb-4">
35-
<div class="forum-board-header">Create Forum manually</div>
36-
<div class="p-3">
37-
<form method="post" action="{{ url_for('forums_explorer.forum_explorer_forum_create') }}">
38-
<div class="form-row">
39-
<div class="form-group col-md-3"><label>forum_id</label><input class="form-control" name="forum_id" placeholder="forum identifier" required></div>
40-
<div class="form-group col-md-3"><label>forum_type</label><input class="form-control" name="forum_type" value="generic" required></div>
41-
<div class="form-group col-md-3"><label>name</label><input class="form-control" name="name" placeholder="Display name"></div>
42-
<div class="form-group col-md-3"><label>url</label><input class="form-control" name="url" placeholder="https://forum.example/"></div>
43-
</div>
44-
<div class="form-group"><label>info</label><textarea class="form-control" name="info" rows="2" placeholder="Optional operator notes"></textarea></div>
45-
<button class="btn btn-primary"><i class="fas fa-plus"></i> Create Forum</button>
46-
</form>
33+
{% if is_admin|default(false) %}
34+
<div class="mb-4">
35+
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#createForumManual" aria-expanded="false" aria-controls="createForumManual">
36+
<i class="fas fa-plus"></i> Create Forum manually
37+
</button>
38+
</div>
39+
<div class="collapse" id="createForumManual">
40+
<div class="forum-board mb-4">
41+
<div class="forum-board-header">Create Forum manually</div>
42+
<div class="p-3">
43+
<form method="post" action="{{ url_for('forums_explorer.forum_explorer_forum_create') }}">
44+
<div class="form-row">
45+
<div class="form-group col-md-3"><label>forum_id</label><input class="form-control" name="forum_id" placeholder="forum identifier" required></div>
46+
<div class="form-group col-md-3"><label>forum_type</label><input class="form-control" name="forum_type" value="generic" required></div>
47+
<div class="form-group col-md-3"><label>name</label><input class="form-control" name="name" placeholder="Display name"></div>
48+
<div class="form-group col-md-3"><label>url</label><input class="form-control" name="url" placeholder="https://forum.example/"></div>
49+
</div>
50+
<div class="form-group"><label>info</label><textarea class="form-control" name="info" rows="2" placeholder="Optional operator notes"></textarea></div>
51+
<button class="btn btn-primary"><i class="fas fa-plus"></i> Create Forum</button>
52+
</form>
53+
</div>
4754
</div>
4855
</div>
4956
{% endif %}

0 commit comments

Comments
 (0)