diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8582b7e386538feb94129877aac67c10b13ac179..35c0bc24a7fac501842c1feabca4ea13b52e8e2e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,16 +15,10 @@ unittest: - docker-compose down -build_nginx: - script: - - DOCKERIT_NO_BRANCH=1 docker-it nginx zoo.smok.co/henrietta/netguru/nginx deployment/nginx - only: - - master - build: stage: build script: - - DOCKERIT_NO_BRANCH=1 docker-it netguru zoo.smok.co/henrietta/netguru/backend . --target runtime + - DOCKERIT_NO_BRANCH=1 docker-it netguru zoo.smok.co/henrietta/netguru . deploy: stage: deploy diff --git a/NOTES.md b/NOTES.md index c83a172552dfdfdeca7dd38d1e3f5ae95e5a4c0b..a45206c9a3552ba15f7ac7c39269ac579495f96a 100644 --- a/NOTES.md +++ b/NOTES.md @@ -21,7 +21,6 @@ I know that I'm ignoring specification, and you are free to call me out on that - but as I got some experience with frontend, I'd rather do **the right thing**. - ## Documentation I couldn't get the DRF documentation to cooperate with me (most @@ -54,7 +53,7 @@ I realize that I would be best practice to deduplicate some code contained within tests, but since I'm running about 1,5 of full-time equvialents you just have to forgive me for sparing the effort to do so. Thanks "from the mountain!" -# The [reaper job](counting/cron.py) +# The [reaper job](counting/cron.py#L27) I came up with the reaper job trying to think up a reasonable solution that wouldn't load the processing server too much. It processes way-past-due @@ -62,7 +61,7 @@ links into a nice compact representation and stores them in the database. Two last days (since the job fires only every 24 hours) are computed on-the-fly, and cached as necessary, for up to 5 minutes. -# Nginx serving static content +# Nginx not serving static content Since it's not ideal for Django to be serving large static files, I tried to optimize it as much as possible by using a streaming iterator. diff --git a/agent/models.py b/agent/models.py index ab2d6777549f8c47eb318840bd152a7ce3869468..6998978dd1cf75445ca384468c2bd218ce48f25a 100644 --- a/agent/models.py +++ b/agent/models.py @@ -4,7 +4,7 @@ from django.db import models class UserAgentStorage(models.Model): user = models.ForeignKey('auth.User', verbose_name='User', db_index=True, on_delete=models.CASCADE) - ua = models.TextField(verbose_name='User agent', null=True, blank=True) + ua = models.TextField(verbose_name='User agent') def __str__(self): return f'{self.user} - {self.ua}' diff --git a/counting/cron.py b/counting/cron.py index a457c138dbed2d5d5a4cadeaff9bb13c568fbbfd..0e97eb333a3abb27d28cb61ee0bd5d79e26b0395 100644 --- a/counting/cron.py +++ b/counting/cron.py @@ -27,10 +27,8 @@ class DayType(enum.IntEnum): class ReaperJob(CronJobBase): """ Reaper's job is to collect dead links within the database and compile a history out of them. - It will delete only links from previous days, only if they have already expired. - - Let's talk a moment about it's logic - days can be divided into one of 3 categories - displayed above in DayType + It will delete only links from previous days, and only for days that have all of their + links expired. """ RUN_EVERY_MINS = 24 * 60 # once each day @@ -46,6 +44,7 @@ class ReaperJob(CronJobBase): StoryOfADay.objects.get(date=date) return DayType.DAY_WITH_HISTORY except StoryOfADay.DoesNotExist: + # this is going to do the right thing even if the iterator's empty if all(item.expired for item in Share.objects.get_for_day(date)): return DayType.DAY_UNPROCESSED_BUT_PROCESSABLE else: @@ -65,11 +64,10 @@ class ReaperJob(CronJobBase): files += 1 else: links += 1 - sod = StoryOfADay(day=cur_day, links=links, - files=files) - logger.info('Historic info for %s compiled, %s files visited, %s links visited', - cur_day, files, links) - entries_compiled.runtime(+1) - sod.save() - share.delete() + sod = StoryOfADay(day=cur_day, links=links, files=files) + logger.info('Historic info for %s compiled, %s files visited, %s links visited', + cur_day, files, links) + entries_compiled.runtime(+1) + sod.save() + share.delete() cur_day = cur_day + datetime.timedelta(days=1) diff --git a/deployment/nginx/Dockerfile b/deployment/nginx/Dockerfile deleted file mode 100644 index f44279ca54aa99ebf3fec7f531eebc25854e0593..0000000000000000000000000000000000000000 --- a/deployment/nginx/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM nginx - -ADD conf.d/ /etc/nginx/conf.d/ diff --git a/deployment/nginx/conf.d/.gitkeep b/deployment/nginx/conf.d/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/netguru/settings.py b/netguru/settings.py index 801da6b699e1da1c2d792ea444dcdfc3c4ec9c55..861a3c8a20d453d38058e21ea80daa98f0329142 100644 --- a/netguru/settings.py +++ b/netguru/settings.py @@ -152,7 +152,6 @@ REST_FRAMEWORK = { 'UNICODE_JSON': True, } - # Configure tracing # ================= OPENTRACING_TRACE_ALL = True diff --git a/shares/migrations/0002_alter_share_resource.py b/shares/migrations/0002_alter_share_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..584cf96c1588c85a6917363f12a16d9491606443 --- /dev/null +++ b/shares/migrations/0002_alter_share_resource.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.6 on 2021-08-26 23:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('shares', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='share', + name='resource', + field=models.TextField( + help_text='URL if this is an URL. Otherwise it will be name of the file as it is on filesystem, then a dot,and then the file name the user submitted it as', + verbose_name='Resource'), + ), + ] diff --git a/shares/tests.py b/shares/tests.py index 154d1b6ce1b2ef058cb8526a850fa38d20d9a59a..a8d789500f6c5fbfb9a18a0a8acd8d62dd69fbee 100644 --- a/shares/tests.py +++ b/shares/tests.py @@ -75,7 +75,8 @@ class TestShares(TestCase): share = Share.objects.get(id=response.json()['url'].rsplit('/', 1)[-1]) share.created_on = datetime.datetime.now() - datetime.timedelta(days=2) share.save() - response = self.api_client.post(f'http://127.0.0.1/api/get/{share.id}', {'password': response.json()['password']}, + response = self.api_client.post(f'http://127.0.0.1/api/get/{share.id}', + {'password': response.json()['password']}, format='json') self.assertEqual(response.status_code, 404) diff --git a/test.sh b/test.sh index 507ad9a4c5ee6899d4727318cfde36da767da497..30ffcf9d0c7f22eff42d5cae0fe397e540baad32 100644 --- a/test.sh +++ b/test.sh @@ -2,5 +2,4 @@ set -e sleep 3 # wait for postgres to start up -python manage.py makemigrations shares python manage.py test --no-input