Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F461238
job_stats.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 17, 11:55 PM
Size
1000 B
Mime Type
text/x-ruby
Expires
Mon, May 19, 11:55 PM (21 h, 54 m)
Engine
blob
Format
Raw Data
Handle
220198
Attached To
rARCHIVING archiving
job_stats.rb
View Options
# Helper class that fetches job stats for the desired clients
class
JobStats
attr_reader
:client_ids
,
:active_jobs
,
:last_jobs
,
:jobs_sizes
,
:jobs_files
# Initializes the object.
def
initialize
(
client_ids
=
nil
)
@client_ids
=
client_ids
fetch_stats
end
private
# Assigns values to:
#
# * active_jobs
# * last_jobs
# * jobs_sizes
# * jobs_files
def
fetch_stats
@active_jobs
=
Job
.
running
@active_jobs
=
@active_jobs
.
where
(
ClientId
:
client_ids
)
if
client_ids
@active_jobs
=
@active_jobs
.
group
(
:ClientId
)
.
count
@last_jobs
=
{}
@jobs_sizes
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
0
}
@jobs_files
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
0
}
jobs
=
Job
.
backup_type
.
order
(
EndTime
:
:asc
)
jobs
=
jobs
.
where
(
ClientId
:
client_ids
)
if
client_ids
jobs
.
each
do
|
job
|
@last_jobs
[
job
.
client_id
]
=
I18n
.
l
(
job
.
end_time
,
format
:
:long
)
if
job
.
end_time
@jobs_sizes
[
job
.
client_id
]
+=
job
.
job_bytes
@jobs_files
[
job
.
client_id
]
+=
job
.
job_files
end
end
end
Event Timeline
Log In to Comment