Skip to content
Snippets Groups Projects
scheduler.py 1019 B
Newer Older
Matevz Erzen's avatar
Matevz Erzen committed
import json
from redis import Redis
from rq import Queue
from rq_scheduler import Scheduler
from wazuh_evidence_collector import wazuh_evidence_collector

Matevz Erzen's avatar
Matevz Erzen committed
f = open('constants.json',)
constants = json.load(f)
f.close()

def remove_jobs(scheduler):
    jobs = scheduler.get_jobs()
    for job in jobs:
        scheduler.cancel(job)

def print_jobs(scheduler):
    jobs = scheduler.get_jobs()
    for job in jobs:
        print(job)

Matevz Erzen's avatar
Matevz Erzen committed
redis = Redis(constants['redis']['ip'], constants['redis']['port'])
q = Queue(constants['redis']['queue'], connection=redis)
scheduler = Scheduler(connection=redis)

# TODO: Remove if needed
remove_jobs(scheduler)

# TODO: Change cron expression and repeat value for production verion.
Matevz Erzen's avatar
Matevz Erzen committed
# Should probably be "0 0 * * * ".
scheduler.cron(
    '* * * * * ',               
    func=wazuh_evidence_collector.run_full_check,                 
    args=[],
    repeat=10,
Matevz Erzen's avatar
Matevz Erzen committed
    queue_name=constants['redis']['queue'],
    use_local_timezone=False
)

# TODO: Remove if needed
print_jobs(scheduler)