Skip to content
Snippets Groups Projects
Commit cb67a7d4 authored by Jiří Setnička's avatar Jiří Setnička
Browse files

DB: Joby mají prioritu

parent 4f355c6f
Branches
No related tags found
1 merge request!124Zjednodušení práce s joby
......@@ -354,6 +354,7 @@ CREATE TABLE jobs (
job_id serial PRIMARY KEY,
type job_type NOT NULL,
state job_state NOT NULL,
priority int NOT NULL DEFAULT 0, -- vyšší číslo = vyšší priorita
user_id int NOT NULL REFERENCES users(user_id), -- komu patří
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- kdy byl založen
finished_at timestamp with time zone DEFAULT NULL, -- kdy doběhl
......
SET ROLE 'mo_osmo';
ALTER TABLE jobs ADD COLUMN
priority int NOT NULL DEFAULT 0;
......@@ -799,6 +799,7 @@ class Job(Base):
job_id = Column(Integer, primary_key=True, server_default=text("nextval('jobs_job_id_seq'::regclass)"))
type = Column(Enum(JobType, name='job_type'), nullable=False)
state = Column(Enum(JobState, name='job_state'), nullable=False)
priority = Column(Integer, nullable=False, server_default=text("0"))
user_id = Column(Integer, ForeignKey('users.user_id'), nullable=False)
description = Column(Text, nullable=False, server_default=text("''::text"))
result = Column(Text, nullable=False, server_default=text("''::text"))
......
......@@ -42,8 +42,8 @@ class TheJob:
self.job = sess.query(db.Job).with_for_update().get(self.job_id)
return self.job
def create(self, type: db.JobType, for_user: db.User) -> db.Job:
self.job = db.Job(type=type, state=db.JobState.preparing, user=for_user)
def create(self, type: db.JobType, for_user: db.User, priority: int = 0) -> db.Job:
self.job = db.Job(type=type, state=db.JobState.preparing, user=for_user, priority=priority)
# Do DB přidáváme nehotový job, protože potřebujeme znát job_id pro založení adresáře
sess = db.get_session()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment