-
Notifications
You must be signed in to change notification settings - Fork 5
Sync page fixes #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tofu-rocketry
wants to merge
18
commits into
apel:dev
Choose a base branch
from
tofu-rocketry:sync
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Sync page fixes #20
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d9ed5d0
Add sync app skeleton
tofu-rocketry 50597db
Correct line endings
tofu-rocketry 05908f3
Add basic models
tofu-rocketry 63e451b
Correct GridSite sync model
tofu-rocketry 07da521
Add urls for sync
tofu-rocketry 54bdc93
Add top level url for sync
tofu-rocketry 4520bf1
Correct sync app name
tofu-rocketry de73ce2
Add sync to apps
tofu-rocketry 97ababb
Add serializer and add difference field
tofu-rocketry 4ff95dc
Remove primary key args as no composite in Django
tofu-rocketry 197eb29
Add unique_together constraint
tofu-rocketry e868607
Add viewset mostly copied from pub to sync
tofu-rocketry 59711a7
Fix Py3 compat and incorrect class
tofu-rocketry da7f890
Fix primary keys
tofu-rocketry cb1b792
Replace Sum with missing Max
tofu-rocketry 3e2ff0d
Fix spelling and app name to use relative path
tofu-rocketry 764ea9c
Update url() to path()
tofu-rocketry ee860fa
*** TEMP DEBUG TRUE ***
tofu-rocketry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class SynchronisationConfig(AppConfig): | ||
| name = 'monitoring.synchronisation' |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.db import models | ||
|
|
||
|
|
||
| class GridSiteSync(models.Model): | ||
| fetched = models.DateTimeField(auto_now=True) | ||
| site = models.CharField(max_length=255) | ||
| year = models.IntegerField() | ||
| month = models.IntegerField() | ||
| site_count = models.IntegerField() | ||
| repository_count = models.IntegerField() | ||
| difference = models.IntegerField() | ||
|
|
||
| class Meta: | ||
| unique_together = ['site', 'year', 'month'] | ||
|
|
||
|
|
||
| class VSuperSummaries(models.Model): | ||
| Site = models.CharField(max_length=255) | ||
| Year = models.IntegerField() | ||
| Month = models.IntegerField() | ||
| NumberOfJobs = models.IntegerField() | ||
|
|
||
| class Meta: | ||
| managed = False | ||
| db_table = 'VSuperSummaries' | ||
| unique_together = ('Site', 'Year', 'Month') | ||
|
|
||
|
|
||
| class VSyncRecords(models.Model): | ||
| Site = models.CharField(max_length=255) | ||
| Year = models.IntegerField() | ||
| Month = models.IntegerField() | ||
| NumberOfJobs = models.IntegerField() | ||
|
|
||
| class Meta: | ||
| managed = False | ||
| db_table = 'VSyncRecords' | ||
| unique_together = ('Site', 'Year', 'Month') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from rest_framework import serializers | ||
|
|
||
| from monitoring.synchronisation.models import GridSiteSync | ||
|
|
||
|
|
||
| class GridSiteSyncSerializer(serializers.HyperlinkedModelSerializer): | ||
| # Override default format with None so that Python datetime is used as | ||
| # ouput format. Encoding will be determined by the renderer and can be | ||
| # formatted by a template filter. | ||
| updated = serializers.DateTimeField(format=None) | ||
|
|
||
| class Meta: | ||
| model = GridSiteSync | ||
| fields = ('url', 'site', 'year', 'month', | ||
| 'site_count', 'repository_count', 'difference') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.test import TestCase | ||
Check noticeCode scanning / CodeQL Unused import Note test
Import of 'TestCase' is not used.
|
||
|
|
||
| # Create your tests here. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from django.urls import include, path | ||
|
|
||
| from rest_framework import routers | ||
|
|
||
| from monitoring.synchronisation import views | ||
|
|
||
| router = routers.SimpleRouter() | ||
| router.register(r'grid', views.GridSiteSyncViewSet) | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| path('', include(router.urls)), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from datetime import datetime, timedelta | ||
|
|
||
| from django.db.models import Max | ||
|
|
||
| from rest_framework import viewsets | ||
| from rest_framework.renderers import TemplateHTMLRenderer | ||
|
|
||
| from monitoring.synchronisation.models import GridSiteSync, VSuperSummaries, VSyncRecords | ||
Check noticeCode scanning / CodeQL Unused import Note
Import of 'VSyncRecords' is not used.
|
||
| from monitoring.synchronisation.serializers import GridSiteSyncSerializer | ||
|
|
||
|
|
||
| class GridSiteSyncViewSet(viewsets.ReadOnlyModelViewSet): | ||
| queryset = GridSiteSync.objects.all() | ||
| serializer_class = GridSiteSyncSerializer | ||
| template_name = 'gridsites.html' | ||
|
|
||
| def retrieve(self, request, pk=None): | ||
| last_fetched = GridSiteSync.objects.aggregate(Max('fetched'))['fetched__max'] | ||
| # If there's no data then last_fetched is None. | ||
| if last_fetched is not None: | ||
| print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20)) | ||
| if last_fetched is None or last_fetched.replace(tzinfo=None) < (datetime.today() - timedelta(hours=1, seconds=20)): | ||
| print('Out of date') | ||
| fetchset = VSuperSummaries.objects.using('grid').raw("SELECT Site, max(LatestEndTime) AS LatestPublish FROM VSuperSummaries WHERE Year=2019 GROUP BY 1;") | ||
| for f in fetchset: | ||
| GridSiteSync.objects.update_or_create(defaults={'updated': f.LatestPublish}, name=f.Site) | ||
| else: | ||
| print('No need to update') | ||
|
|
||
| response = super(GridSiteSyncViewSet, self).retrieve(request) | ||
| date = response.data['updated'].replace(tzinfo=None) | ||
|
|
||
| # Wrap data in a dict so that it can display in template. | ||
| if type(request.accepted_renderer) is TemplateHTMLRenderer: | ||
| # Single result put in list to work with same HTML template. | ||
| response.data = {'sites': [response.data], 'last_fetched': last_fetched} | ||
|
|
||
| diff = datetime.today() - date | ||
| if diff <= timedelta(days=7): | ||
| response.data['returncode'] = 0 | ||
| response.data['stdout'] = "OK [ last published %s days ago: %s ]" % (diff.days, date.strftime("%Y-%m-%d")) | ||
| elif diff > timedelta(days=7): | ||
| response.data['returncode'] = 1 | ||
| response.data['stdout'] = "WARNING [ last published %s days ago: %s ]" % (diff.days, date.strftime("%Y-%m-%d")) | ||
| else: | ||
| response.data['returncode'] = 3 | ||
| response.data['stdout'] = "UNKNOWN" | ||
|
|
||
| return response | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused import Note