Skip to content

Commit

Permalink
Periodic reconciler only on change (#649)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Oct 29, 2023
1 parent 0d06a8f commit 3d9e16f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion osism/tasks/reconciler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def celery_init_worker(**kwargs):
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
sender.add_periodic_task(
settings.INVENTORY_RECONCILER_SCHEDULE, run.s(), expires=10
settings.INVENTORY_RECONCILER_SCHEDULE, run_on_change.s(), expires=10
)


Expand All @@ -48,6 +48,23 @@ def run(self):
lock.release()


@app.task(bind=True, name="osism.tasks.reconciler.run_on_change")
def run_on_change(self):
lock = Redlock(
key="lock_osism_tasks_reconciler_run_on_change",
masters={redis},
auto_release_time=60,
)

if lock.acquire(timeout=20):
p = subprocess.Popen(
"/run.sh", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
p.wait()

lock.release()


@app.task(bind=True, name="osism.tasks.reconciler.sync_inventory_with_netbox")
def sync_inventory_with_netbox(self):
lock = Redlock(
Expand Down

0 comments on commit 3d9e16f

Please sign in to comment.