Skip to content

Commit

Permalink
Fix: Notifications
Browse files Browse the repository at this point in the history
### Changelog:
* Fix: History lines notification last call fix.
* Fix: Send notifications for Project and History models.
* Chore: Export `ExecutionTimeField` for EE.
* Chore: Bump version to `2.0.0`.
* Chore: Update frontend dependencies.
* Chore: Rename dir with frontend src.

See merge request polemarch/ce!266
  • Loading branch information
onegreyonewhite committed Sep 13, 2022
2 parents 59ff183 + 9f9e0a5 commit b1b3ee4
Show file tree
Hide file tree
Showing 48 changed files with 948 additions and 1,280 deletions.
10 changes: 5 additions & 5 deletions doc/api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ info:
url: https://gitlab.com/vstconsulting/polemarch.git
Request:
- name: Question
url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%202.0.0b2
url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%202.0.0
- name: Bug report
url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%202.0.0b2
url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%202.0.0
- name: Feature request
url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D=
x-menu:
Expand Down Expand Up @@ -66,9 +66,9 @@ info:
logout_url: /account/logout/
login_url: /account/login/
x-versions:
application: 2.0.0b2
library: 2.0.0b2
vstutils: 5.0.7
application: 2.0.0
library: 2.0.0
vstutils: 5.0.10
django: 3.2.15
djangorestframework: 3.13.1
drf_yasg: 1.21.3
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ services:
timeout: 3s
retries: 3
command: centrifugo
ulimits:
nofile:
soft: 65535
hard: 65535

volumes:
data-volume:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const HISTORY_MODELS = ['History', 'OneHistory', 'ProjectHistory'];
const HISTORY_LIST_PATHS = ['/history/', '/project/{id}/history/'];
const HISTORY_DETAIL_PATHS = ['/history/{id}/', '/project/{id}/history/{history_id}/'];

export { ExecutionTimeField };

export class ProjectBasedFkField extends spa.fields.fk.fk.FKField {
_formatQuerysetPath(queryset) {
return super
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "APP_ENV=prod webpack",
"devBuild": "webpack",
"lint": "eslint --ext .js,.vue frontend_src_new/"
"lint": "eslint --ext .js,.vue frontend_src/"
},
"devDependencies": {
"@babel/core": "^7.16.7",
Expand Down
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__ = "2.0.0b3"
__version__ = "2.0.0"

prepare_environment(**default_settings)
4 changes: 4 additions & 0 deletions polemarch/main/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.utils import timezone
from vstutils.utils import tmp_file, KVExchanger, raise_context
from vstutils.tools import get_file_value

from .hosts import Inventory
from .tasks import History, Project
from ...main.utils import CmdExecutor, AnsibleArgumentsReference, PMObject
Expand Down Expand Up @@ -134,6 +135,9 @@ def execute(self, cmd: Iterable[Text], cwd: Text):
ret = super().execute(new_cmd, cwd)
if self.notificator:
self.notificator.disconnect_all()
with self.notificator_lock:
if self.notificator.queue:
self.notificator.send()
return ret


Expand Down
120 changes: 0 additions & 120 deletions polemarch/main/settings.ini

This file was deleted.

5 changes: 5 additions & 0 deletions polemarch/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ class GitCloneSection(GitSection):
},
}

NOTIFY_WITHOUT_QUEUE_MODELS = [
'main.History',
'main.Project',
]

CLONE_RETRY = rpc.getint('clone_retry_count', fallback=5)

# ACL settings
Expand Down
10 changes: 10 additions & 0 deletions polemarch/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import json
from os.path import dirname
from vstutils.models.cent_notify import Notificator

try:
from yaml import CLoader as Loader, CDumper as Dumper, load, dump
Expand All @@ -24,6 +25,7 @@
Executor,
UnhandledExecutor, ON_POSIX,
)
from ..main.settings import NOTIFY_WITHOUT_QUEUE_MODELS


from . import __file__ as file
Expand Down Expand Up @@ -341,3 +343,11 @@ def get_inventory_data(self, raw_data):

class AnsibleConfigParser(PMAnsible):
ref_name = 'config'


class PolemarchNotificator(Notificator):
def create_notification_from_instance(self, instance):
super().create_notification_from_instance(instance)
# pylint: disable=protected-access
if instance.__class__._meta.label in NOTIFY_WITHOUT_QUEUE_MODELS and self.channel != 'history_lines':
self.send()
2 changes: 2 additions & 0 deletions polemarch/settings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[web]
notificator_client_class = {LIB_NAME}.main.utils.PolemarchNotificator
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Docs
vstutils[doc]~=5.0.5
vstutils[doc]~=5.0.10
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main
vstutils[rpc,ldap,doc,prod]~=5.0.7
vstutils[rpc,ldap,doc,prod]~=5.0.10
docutils~=0.16.0
markdown2~=2.4.0

Expand Down
19 changes: 19 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,25 @@ def test_template(self):
self.assertEqual(results[3]['data']['initiator'], task_template['id'])
self.assertEqual(results[3]['data']['mode'], 'playbook.yml')

def test_notificator(self):
class DummyClient:
def add(*args):
pass

def send(*args):
pass

with self.patch(
f'{settings.VST_PROJECT_LIB_NAME}.main.utils.PolemarchNotificator.get_client',
return_value=DummyClient()
) as client_getter:
self.assertEqual(client_getter.call_count, 0)
self.bulk_transactional([self.sync_project_bulk_data()])
self.assertEqual(client_getter.call_count, 1)
client_getter.call_count = 0
self.bulk_transactional([self.execute_module_bulk_data()])
self.assertEqual(client_getter.call_count, 2)


@own_projects_dir
class VariableTestCase(BaseProjectTestCase):
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require('dotenv').config();
const isProd = process.env.APP_ENV === 'prod';

const KB = 1024;
const frontendSrc = path.resolve(__dirname, 'frontend_src_new');
const frontendSrc = path.resolve(__dirname, 'frontend_src');

module.exports = {
mode: isProd ? 'production' : 'development',
Expand Down
Loading

0 comments on commit b1b3ee4

Please sign in to comment.