Commit 06d701d1 authored by Bram Daams's avatar Bram Daams
Browse files

some more cron lines; get_jobid and find_by_jobid registry methods

parent 09036a72
Pipeline #34844 passed with stage
in 39 seconds
# Sample cron file that does almost nothing
# some comment
1 0 * * * root JOB_ID=false1 /bin/false
2 0 * * * root JOB_ID=false2 /bin/false
# bla bla
1 0 * * * root JOB_ID=falsetest1 /bin/false
2 0 * * * root JOB_ID=falsetest2 /bin/false
3 0 * * * root JOB_ID=unknown /bin/false
4 0 * * * root /bin/false
......@@ -5,6 +5,7 @@ import arrow
import json
import hashlib
import platform
import re
class hcCred:
......@@ -38,19 +39,29 @@ class hcRegistry:
md5.update(job.command.encode('utf-8'))
return md5.hexdigest()
def get_jobid(self, job):
regex = r"JOB_ID=(\w*)"
match = re.match(regex, job.command)
if match:
return match.group(1)
def find_by_hash(self, job):
h = self.get_hash(job)
return next((elem for elem in self.data if elem['hash'] == h), False)
def find_by_job_id(self, job):
pass
def find_by_jobid(self, job):
j = self.get_jobid(job)
return next((elem for elem in self.data if elem['JOB_ID'] == j), False)
def get_id(self, job):
r = self.find_by_hash(job)
if r:
return r['HC_ID']
# r = self.find_by_job_id(job)
r = self.find_by_jobid(job)
if r:
return r['HC_ID']
return False
def register(self, id):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment