Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit f0255a8

Browse files
authored
Merge pull request #73 from omniscrapper/statistics-page
Tasks statuses page
2 parents c482bdb + f06d707 commit f0255a8

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

apps/web/assets/stylesheets/components/_index.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@
66
margin-top: 30px;
77
margin-bottom: 30px;
88
}
9+
10+
table {
11+
tr.failure {
12+
background-color: #f8d7da;
13+
}
14+
tr.success {
15+
background-color: #d4edda;
16+
}
17+
tr.running {
18+
background-color: #fff3cd;
19+
}
20+
}
921
}

apps/web/controllers/home/index.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ module Controllers
33
module Home
44
class Index
55
include Web::Action
6+
include Import[
7+
task_repo: 'repositories.scrapping.start_event'
8+
]
9+
10+
expose :tasks
611

712
def call(params)
13+
@tasks = task_repo.tasks_statuses
814
end
915
end
1016
end
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
.container
2-
%h1= 'Welcome'
2+
%h1= 'OmniScrapperHQ Status'
3+
4+
%table.table.table-bordered.table-hover.table-sm
5+
%thead
6+
%tr
7+
%th Task
8+
%th Job
9+
%th State
10+
%th Time elapsed
11+
%th
12+
%tbody
13+
- tasks.each do |task|
14+
%tr{class: task.status}
15+
%td= task.task_id
16+
%td= task.job_id
17+
%td= task.status
18+
%td= task.elapsed_time
19+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Hanami::Model.migration do
2+
change do
3+
alter_table :scrapping_started_events do
4+
add_column :url, String, null: false
5+
end
6+
end
7+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
module Scrapping
22
class StartEventRepository < Hanami::Repository
33
self.relation = :scrapping_started_events
4+
5+
def tasks_statuses
6+
root.read <<-SQL
7+
SELECT
8+
task_id,
9+
job_id,
10+
schema_id,
11+
url,
12+
finished_at - started_at AS elapsed_time,
13+
CASE
14+
WHEN status IS NULL THEN 'running'
15+
ELSE status
16+
END
17+
18+
FROM (
19+
SELECT
20+
"tasks"."id" AS task_id,
21+
"tasks"."schema_id" AS schema_id,
22+
23+
"scrapping_started_events"."job_id" AS job_id,
24+
"scrapping_started_events"."url" AS url,
25+
"scrapping_finished_events"."event_type" AS status,
26+
27+
"scrapping_started_events"."created_at" AS started_at,
28+
"scrapping_finished_events"."created_at" AS finished_at
29+
30+
FROM "scrapping_started_events"
31+
32+
INNER JOIN "tasks"
33+
ON "tasks"."id" = "scrapping_started_events"."task_id"
34+
35+
LEFT OUTER JOIN "scrapping_finished_events"
36+
ON (
37+
"scrapping_started_events"."job_id" = "scrapping_finished_events"."job_id"
38+
AND
39+
"scrapping_started_events"."task_id" = "scrapping_finished_events"."task_id"
40+
AND
41+
"scrapping_started_events"."url" = "scrapping_finished_events"."url"
42+
)
43+
44+
ORDER BY "scrapping_started_events"."created_at" DESC
45+
) AS events
46+
LIMIT 20
47+
SQL
48+
end
449
end
550
end

lib/omniscrapper_hq/repositories/task_repository.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class TaskRepository < Hanami::Repository
77
has_many :test_results
88
belongs_to :schema
99
belongs_to :site
10+
has_many :scrapping_finished_events
11+
has_many :scrapping_started_events
1012
end
1113

1214
def delete_with_dependencies(id)

0 commit comments

Comments
 (0)