Skip to content

Commit 5999de7

Browse files
authored
Allow use of multiple rqworkers (#161)
1 parent efca97d commit 5999de7

File tree

10 files changed

+32
-22
lines changed

10 files changed

+32
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.retry
55
*.code-workspace
66
*.sw?
7+
.venv

README.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ Use this syntax if your redis is installed with sentinet architecture (multiple
234234
the second set of variables if you wish to split your cache database from your
235235
webhooks database.
236236

237+
[source,yaml]
238+
----
239+
netbox_rqworker_processes: 1
240+
----
241+
242+
Specify how many request queue workers should be started by the systemd service.
243+
You can leave this at the default of 1, unless you have a large number of reports,
244+
scripts and other background tasks.
245+
237246
[source,yaml]
238247
----
239248
netbox_config:

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ netbox_pip_constraints:
100100

101101
netbox_keep_uwsgi_updated: false
102102
netbox_uwsgi_options: {}
103+
netbox_rqworker_processes: 1

handlers/main.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
- name: restart netbox-rqworker.service
2121
systemd:
22-
name: netbox-rqworker.service
22+
name: "netbox-rqworker@{{ item }}.service"
2323
state: restarted
2424
daemon_reload: true
25-
26-
- name: reload netbox-rqworker.service
27-
systemd:
28-
name: netbox-rqworker.service
29-
state: reloaded
25+
with_sequence: count="{{ netbox_rqworker_processes }}"

molecule/default/converge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
role_attr_flags: CREATEDB,NOSUPERUSER
2828
## REDIS server install
2929
redis_bind: 127.0.0.1
30+
netbox_rqworker_processes: 2
3031
roles:
3132
- geerlingguy.postgresql
3233
- davidwittman.redis

molecule/default/tests/test_default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def test_services(host):
1010
services = [
1111
"netbox.socket",
1212
"netbox.service",
13-
"netbox-rqworker.service"
13+
"netbox-rqworker@1.service"
14+
"netbox-rqworker@2.service"
1415
]
1516
for service in services:
1617
s = host.service(service)

tasks/deploy_netbox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
py_compile.compile(f, c); os.remove(c)\""
8181
notify:
8282
- reload netbox.service
83-
- reload netbox-rqworker.service
83+
- restart netbox-rqworker.service
8484

8585
- name: Generate LDAP configuration for NetBox if enabled
8686
template:

tasks/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
- name: Install NetBox-rqworker service unit file
107107
template:
108108
src: netbox-rqworker.service.j2
109-
dest: /lib/systemd/system/netbox-rqworker.service
109+
dest: /lib/systemd/system/netbox-rqworker@.service
110110
notify:
111111
- restart netbox-rqworker.service
112112

@@ -121,9 +121,10 @@
121121

122122
- name: Start and enable netbox-rqworker.service
123123
systemd:
124-
name: netbox-rqworker.service
124+
name: "netbox-rqworker@{{ item }}.service"
125125
state: started
126126
enabled: true
127+
with_sequence: count="{{ netbox_rqworker_processes }}"
127128

128129
- name: Restore the previous Ansible Python interpreter
129130
set_fact:

templates/netbox-rqworker.service.j2

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{{ ansible_managed | comment }}
22
[Unit]
3-
Description=NetBox RQ-Worker
4-
Documentation=http://netbox.readthedocs.io/en/{{ 'latest' if netbox_git else 'stable' }}/installation/3-http-daemon/#supervisord-installation
5-
After=syslog.target
3+
Description=NetBox Request Queue Worker %i
4+
Documentation=https://docs.netbox.dev/
5+
After=network-online.target
6+
Wants=network-online.target
67

78
[Service]
9+
Type=simple
10+
811
WorkingDirectory={{ netbox_shared_path }}
9-
ExecStart={{ netbox_virtualenv_path }}/bin/python \
10-
{{ netbox_current_path }}/netbox/manage.py rqworker
11-
ExecReload=/bin/kill -1 $MAINPID
12-
ExecStop=/bin/kill -2 $MAINPID
12+
ExecStart={{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py rqworker high default low
13+
1314
StandardOutput=journal
1415
StandardError=journal
1516
User={{ netbox_user }}
1617
Group={{ netbox_group }}
1718
Restart=on-failure
18-
#SuccessExitStatus=15 17 29 30
19-
KillSignal=SIGQUIT
20-
StandardError=syslog
19+
RestartSec=30
20+
2121
NotifyAccess=all
22-
PrivateTmp=yes
22+
PrivateTmp=true
2323
ProtectSystem=full
2424
DeviceAllow=/dev/null rw
2525
DeviceAllow=/dev/urandom r

tests/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
shell: cat /srv/netbox/shared/uwsgi.ini
1414
changed_when: false
1515
- name: NetBox rq-worker service status # noqa 303 305
16-
shell: "systemctl status netbox-rqworker.service"
16+
shell: "systemctl status netbox-rqworker@1.service"
1717
changed_when: false
1818
- name: NetBox application log # noqa 305
1919
shell: cat /srv/netbox/shared/application.log

0 commit comments

Comments
 (0)