Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PythonLibs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheCodeLabs
PythonLibs
Commits
730ad55e
Commit
730ad55e
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
added CachedService
parent
5dacb367
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PythonLibs/CachedService.py
+29
-0
29 additions, 0 deletions
PythonLibs/CachedService.py
PythonLibs/__init__.py
+1
-0
1 addition, 0 deletions
PythonLibs/__init__.py
with
30 additions
and
0 deletions
PythonLibs/CachedService.py
0 → 100644
+
29
−
0
View file @
730ad55e
import
abc
from
abc
import
ABC
from
datetime
import
datetime
from
typing
import
Dict
class
CachedService
(
ABC
):
def
__init__
(
self
,
fetchThresholdInSeconds
:
int
):
self
.
_fetchThresholdInSeconds
=
fetchThresholdInSeconds
self
.
_lastFetchTimestamp
=
0
self
.
_data
=
None
def
get_data
(
self
)
->
Dict
:
if
self
.
__is_data_obsolete
():
self
.
_data
=
self
.
_fetch_data
()
return
self
.
_data
def
__is_data_obsolete
(
self
)
->
bool
:
now
=
datetime
.
now
().
timestamp
()
if
(
now
-
self
.
_lastFetchTimestamp
)
>
self
.
_fetchThresholdInSeconds
:
self
.
_lastFetchTimestamp
=
now
return
True
self
.
_lastFetchTimestamp
=
now
return
False
@abc.abstractmethod
def
_fetch_data
(
self
)
->
Dict
:
pass
This diff is collapsed.
Click to expand it.
PythonLibs/__init__.py
+
1
−
0
View file @
730ad55e
from
PythonLibs.DefaultLogger
import
DefaultLogger
from
PythonLibs.MailHandler
import
MailHandler
from
PythonLibs.CachedService
import
CachedService
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment