Skip to content

Commit 1669b98

Browse files
committed
Init migration, connect things
1 parent 3f132ac commit 1669b98

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1+
import asyncio
2+
import logging
3+
14
from dispatcher.main import DispatcherMain
5+
6+
from ansible_base.lib.utils.db import get_pg_notify_params
7+
28
from django.core.management.base import BaseCommand
9+
from django.db import connection
10+
from django.core.cache import cache
11+
12+
logger = logging.getLogger(__name__)
313

414

515
class Command(BaseCommand):
616
help = "Runs bug checking sanity checks, gets scale metrics, and recommendations for Role Based Access Control"
717

818
def handle(self, *args, **options):
19+
psycopg_params = get_pg_notify_params()
20+
921
dispatcher_config = {
1022
"producers": {
1123
"brokers": {
12-
"pg_notify": {"conninfo": settings.PG_NOTIFY_DSN_SERVER},
13-
# TODO: sanitize or escape channel names on dispatcher side
24+
"pg_notify": psycopg_params,
1425
"channels": ["dab_broadcast"],
1526
},
16-
# NOTE: I would prefer to move the activation monitoring
17-
# from worker to activation, but that is more work
1827
"scheduled": {},
1928
},
20-
"pool": {"max_workers": 4},
29+
"pool": {"max_workers": 4}, # TODO: to settings
2130
}
2231

23-
DispatcherMain()
32+
loop = asyncio.get_event_loop()
33+
dispatcher = DispatcherMain(dispatcher_config)
34+
35+
# Borrowed from eda-server, ensure the database connection is closed
36+
connection.close()
37+
cache.close()
38+
try:
39+
loop.run_until_complete(dispatcher.main())
40+
except KeyboardInterrupt:
41+
logger.info("run_worker_dispatch entry point leaving")
42+
finally:
43+
loop.close()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.2.16 on 2025-02-04 21:22
2+
3+
from django.db import migrations, models
4+
import uuid
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Task',
17+
fields=[
18+
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, help_text='UUID that corresponds to the dispatcher task uuid', primary_key=True, serialize=False)),
19+
('state', models.CharField(choices=[('completed', 'Completed'), ('failed', 'Failed'), ('running', 'Running'), ('waiting', 'Waiting')], default='waiting', help_text='Choices of this field track with acknowledgement and completion of a task', max_length=15)),
20+
('name', models.TextField(help_text='Importable path for class or method')),
21+
('created', models.DateTimeField(auto_now_add=True, help_text='Time the publisher (submitter) of this task call created it, approximately the time of submission as well')),
22+
('started_at', models.DateTimeField(help_text='Time of acknowledgement, also approximately the time the task starts', null=True)),
23+
('finished_at', models.DateTimeField(help_text='Time task is cleared (whether failed or succeeded), may be unused if set to auto-delete', null=True)),
24+
],
25+
),
26+
]

ansible_base/task/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Task(models.Model):
2828
state = models.CharField(
2929
choices=[(s, s.title()) for s in sorted(vars(TASK_STATES).values())],
3030
default=TASK_STATES.WAITING,
31+
max_length=15,
3132
help_text=_('Choices of this field track with acknowledgement and completion of a task'),
3233
)
3334
name = models.TextField(help_text=_('Importable path for class or method'))

test_app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'ansible_base.rest_pagination',
7070
'ansible_base.rbac',
7171
'ansible_base.oauth2_provider',
72+
'ansible_base.task',
7273
'test_app',
7374
'django_extensions',
7475
'debug_toolbar',

0 commit comments

Comments
 (0)