from persistent import Persistent

from backend.wharfrat import db

# Ensure that the jobs key is present
# in the root
if 'jobs' not in db:
    from BTrees.OOBTree import OOBTree
    db['jobs'] = OOBTree()

jobs = db['jobs']


class Job(Persistent):

    def __init__(self, name):
        if name in jobs:
            raise ValueError('That job name is in use')

        self.name = name
        jobs[name] = self
        db['jobs'] = jobs
