Skip to content

Commit

Permalink
1.5.1
Browse files Browse the repository at this point in the history
Changelog:
* Fix build and optimize `CRONTAB` periodic tasks saving performance.

See merge request polemarch/ce!171
  • Loading branch information
onegreyonewhite committed Nov 30, 2019
2 parents ba18ebe + 953f9aa commit 8b5400b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
8 changes: 3 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
image: onegreyonewhite/tox:tox

variables:
TESTS: "polemarch.main.tests"
GET_SOURCES_ATTEMPTS: 3
ARTIFACT_DOWNLOAD_ATTEMPTS: 3
RESTORE_CACHE_ATTEMPTS: 3
DJANGO_LOG_LEVEL: 'ERROR'
DJANGO_LOG_LEVEL: 'DEBUG'
TOX_ARGS: "--workdir /cache/.tox_polemarch_${CI_BUILD_REF_NAME}"
CCACHE_DIR: /cache/.ccache
CC: ccache gcc
Expand Down Expand Up @@ -98,7 +97,6 @@ master_coverage:
<<: *branch_tests
variables:
TOX_ENVS: "py37-coverage"
except:
only:
refs:
- master
Expand Down Expand Up @@ -202,7 +200,7 @@ publish_pypi:
- $PYPI_UPLOAD_PASSWORD
- $PYPI_UPLOAD_NAME
script:
- twine upload -u ${PYPI_UPLOAD_NAME} -p ${PYPI_UPLOAD_PASSWORD} dist/*.tar.gz dist/*.whl
- make twine


publish_release:
Expand All @@ -220,6 +218,6 @@ publish_release:
before_script:
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git push https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/vstconsulting/polemarch.git "${CI_COMMIT_TAG}"
- git push https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/vstconsulting/polemarch.git ${CI_COMMIT_TAG} || echo "Failed to upload to github."
script:
- make test ENVS=release
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PY = python2
PY = python
PIP = $(PY) -m pip
PY_VERSION = $(shell $(PY) --version 2>&1 | tail -c +8)
PYTHON_BIN = $(shell $(PY) -c 'import sys, os; print(os.path.dirname(sys.executable))')
Expand All @@ -12,7 +12,7 @@ TESTS =
NAMEBASE = polemarch
USER = $(NAMEBASE)
NAME = $(NAMEBASE)
VER = $(shell $(PY) -c 'import $(NAME); print($(NAME).__version__)')
VER = $(shell $(PY) setup.py --version | tr -d '\n')
PROJECT_CTL = $(NAME)ctl
MAIN_APP = main
VSTUTILS_REQ = $(shell cat requirements-doc.txt | grep vstutils | sed 's/\[.*\]/[doc]/')
Expand Down Expand Up @@ -86,7 +86,7 @@ pylint:
tox -e pylint

build: build-clean print_vars
-rm -rf dist
# -rm -rf dist
$(PY) setup.py sdist -v

pre_compile: build-clean print_vars
Expand All @@ -95,7 +95,7 @@ pre_compile: build-clean print_vars
$(PIP) install -U $(VSTUTILS)

compile: pre_compile
-rm -rf dist
# -rm -rf dist
$(PY) setup.py compile -v

wheel: pre_compile
Expand Down Expand Up @@ -208,3 +208,9 @@ deploy:

destroy:
ansible-playbook destroy-openstack.yml -v --private-key $(OPENSTACK_KEY) $(DEPLOY_ARGS)

twine:
for file in $(shell find dist/*.{tar.gz,whl} | grep ${NAME} | grep ${VER}); do \
echo $$file; \
twine upload -u $(PYPI_UPLOAD_NAME) -p $(PYPI_UPLOAD_PASSWORD) $$file || echo "Filed to upload ${file}"; \
done
2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'),
}

__version__ = "1.5.0"
__version__ = "1.5.1"

prepare_environment(**default_settings)
42 changes: 24 additions & 18 deletions polemarch/main/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,23 @@ def save_to_beat(instance: PeriodicTask, **kwargs) -> NoReturn:
if instance.type == "INTERVAL":
units = IntervalSchedule.SECONDS
secs = instance.get_schedule()
schedule, _ = IntervalSchedule.objects.get_or_create(every=secs,
period=units)
manager.create(interval=schedule,
name=str(instance.id),
task=task,
args=json.dumps([instance.id]))
schedule, _ = IntervalSchedule.objects.get_or_create(every=secs, period=units)
manager.create(
interval=schedule,
name=str(instance.id),
task=task,
args=json.dumps([instance.id])
)
elif instance.type == "CRONTAB":
cron_data = instance.crontab_kwargs
cron_data['timezone'] = settings.TIME_ZONE
schedule, _ = CrontabSchedule.objects.get_or_create(**cron_data)
schedule.timezone = settings.TIME_ZONE
schedule.save()
manager.create(crontab=schedule,
name=str(instance.id),
task=task,
args=json.dumps([instance.id]))
manager.create(
crontab=schedule,
name=str(instance.id),
task=task,
args=json.dumps([instance.id])
)


@receiver(signals.post_delete, sender=PeriodicTask)
Expand All @@ -244,18 +246,22 @@ def delete_from_beat(instance: PeriodicTask, **kwargs) -> NoReturn:
return
manager = django_celery_beat.models.PeriodicTask.objects
celery_tasks = manager.filter(name=str(instance.id))
types_dict = {
'crontab_id': CrontabSchedule,
'interval_id': IntervalSchedule
}
qs_dict = {i: [] for i in types_dict}
for task in celery_tasks:
qs_dict = {
'crontab_id': CrontabSchedule.objects.all(),
'interval_id': IntervalSchedule.objects.all(),
}
for field in ['crontab_id', 'interval_id']:
for field in qs_dict:
pk = getattr(task, field)
if pk is None:
continue
others = manager.filter(**{field: pk}).exclude(pk=task.id)
if not others.exists():
qs_dict[field].get(id=pk).delete()
qs_dict[field].append(pk)
for key, values in qs_dict.items():
if values:
types_dict[key].objects.filter(id__in=values).delete()
celery_tasks.delete()


Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ project = 'Polemarch'
repo = vstconsulting/polemarch
assets =
dist/polemarch-{release}.tar.gz
dist/polemarch-{release}-py3-none-any.whl
dist/polemarch-{release}-cp35-cp35m-manylinux1_x86_64.whl
dist/polemarch-{release}-cp36-cp36m-manylinux1_x86_64.whl
dist/polemarch-{release}-cp37-cp37m-manylinux1_x86_64.whl
Expand Down
5 changes: 3 additions & 2 deletions tox_build.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py35-build,py{35,36,37}-wheel,auditwheel
# envlist = py35-build,py{35,36,37}-wheel,auditwheel
envlist = py35-{build,wheel}
skipsdist = True

[testenv]
Expand Down Expand Up @@ -35,6 +36,6 @@ whitelist_externals =
rm
ls
commands =
bash -c "for whl in `ls dist/*.whl | grep -v manylinux`; do auditwheel repair $whl -w dist/; rm $whl; done"
bash -c "for whl in `ls dist/*.whl | grep -v manylinux | grep -v none-any`; do auditwheel repair $whl -w dist/; rm $whl; done"
deps =
auditwheel

0 comments on commit 8b5400b

Please sign in to comment.