Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
85c04a8a
Commit
85c04a8a
authored
May 07, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track historical active user count.
parent
fbb011be
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
4 deletions
+84
-4
app/models/historical_data.rb
app/models/historical_data.rb
+20
-0
app/workers/historical_data_worker.rb
app/workers/historical_data_worker.rb
+10
-0
app/workers/ldap_sync_worker.rb
app/workers/ldap_sync_worker.rb
+1
-3
db/migrate/20150507194350_create_historical_data.rb
db/migrate/20150507194350_create_historical_data.rb
+10
-0
db/schema.rb
db/schema.rb
+8
-1
spec/models/historical_data_spec.rb
spec/models/historical_data_spec.rb
+35
-0
No files found.
app/models/historical_data.rb
0 → 100644
View file @
85c04a8a
class
HistoricalData
<
ActiveRecord
::
Base
validate
:date
,
presence:
true
# HistoricalData.during((Date.today - 1.year)..Date.today).average(:active_user_count)
scope
:during
,
->
(
range
)
{
where
(
date:
range
)
}
class
<<
self
def
track!
create!
(
date:
Date
.
today
,
active_user_count:
User
.
active
.
count
)
end
# HistoricalData.at(Date.new(2014, 1, 1)).active_user_count
def
at
(
date
)
find_by
(
date:
date
)
end
end
end
app/workers/historical_data_worker.rb
0 → 100644
View file @
85c04a8a
class
HistoricalDataWorker
include
Sidekiq
::
Worker
include
Sidetiq
::
Schedulable
recurrence
{
daily
.
hour_of_day
(
12
)
}
def
perform
HistoricalData
.
track!
end
end
app/workers/ldap_sync_worker.rb
View file @
85c04a8a
...
...
@@ -2,9 +2,7 @@ class LdapSyncWorker
include
Sidekiq
::
Worker
include
Sidetiq
::
Schedulable
# We check if we are in a Sidekiq server process because of a bug in Sidetiq
# 0.6.1 which was giving Unicorn trouble (throwing a Redis::InheritedError).
if
Gitlab
.
config
.
ldap
.
enabled
&&
Sidekiq
.
server?
if
Gitlab
.
config
.
ldap
.
enabled
HOUR
=
Gitlab
.
config
.
ldap
.
schedule_sync_hour
MINUTE
=
Gitlab
.
config
.
ldap
.
schedule_sync_minute
...
...
db/migrate/20150507194350_create_historical_data.rb
0 → 100644
View file @
85c04a8a
class
CreateHistoricalData
<
ActiveRecord
::
Migration
def
change
create_table
:historical_data
do
|
t
|
t
.
date
:date
,
null:
false
t
.
integer
:active_user_count
t
.
timestamps
end
end
end
db/schema.rb
View file @
85c04a8a
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2015050
2064022
)
do
ActiveRecord
::
Schema
.
define
(
version:
2015050
7194350
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -132,6 +132,13 @@ ActiveRecord::Schema.define(version: 20150502064022) do
t
.
boolean
"is_sample"
,
default:
false
end
create_table
"historical_data"
,
force:
true
do
|
t
|
t
.
date
"date"
,
null:
false
t
.
integer
"active_user_count"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
create_table
"identities"
,
force:
true
do
|
t
|
t
.
string
"extern_uid"
t
.
string
"provider"
...
...
spec/models/historical_data_spec.rb
0 → 100644
View file @
85c04a8a
require
'spec_helper'
describe
HistoricalData
do
before
do
(
1
..
12
).
each
do
|
i
|
HistoricalData
.
create!
(
date:
Date
.
new
(
2014
,
i
,
1
),
active_user_count:
i
*
100
)
end
end
describe
".during"
do
it
"returns the historical data during the given period"
do
expect
(
HistoricalData
.
during
(
Date
.
new
(
2014
,
1
,
1
)
..
Date
.
new
(
2014
,
12
,
31
)).
average
(
:active_user_count
)).
to
eq
(
650
)
end
end
describe
".at"
do
it
"returns the historical data at the given date"
do
expect
(
HistoricalData
.
at
(
Date
.
new
(
2014
,
8
,
1
)).
active_user_count
).
to
eq
(
800
)
end
end
describe
".track!"
do
before
do
allow
(
User
).
to
receive
(
:active
).
and_return
([
1
,
2
,
3
,
4
,
5
])
end
it
"creates a new historical data record"
do
HistoricalData
.
track!
data
=
HistoricalData
.
last
expect
(
data
.
date
).
to
eq
(
Date
.
today
)
expect
(
data
.
active_user_count
).
to
eq
(
5
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment