@@ -52,6 +52,13 @@ class JobsRequestModel(ResponseModel):
5252 title = "Restart" ,
5353 description = "Restart job with given id" ,
5454 )
55+ priority : tuple [int , int ] | None = Field (
56+ None ,
57+ title = "Priority" ,
58+ descriprion = "Set priority of job with given id. "
59+ "First value is job id, second is priority" ,
60+ example = [42 , 3 ],
61+ )
5562
5663
5764class JobsItemModel (RequestModel ):
@@ -66,7 +73,8 @@ class JobsItemModel(RequestModel):
6673 title = "User ID" ,
6774 description = "ID of the user who started the job" ,
6875 )
69- message : str = Field (None , title = "Status description" , example = "Encoding 24%" )
76+ priority : int = Field (3 , title = "Priority" , example = 3 )
77+ message : str = Field (..., title = "Status description" , example = "Encoding 24%" )
7078 ctime : int | None = Field (None , title = "Created at" , example = f"{ int (time .time ())} " )
7179 stime : int | None = Field (None , title = "Started at" , example = f"{ int (time .time ())} " )
7280 etime : int | None = Field (None , title = "Finished at" , example = f"{ int (time .time ())} " )
@@ -161,6 +169,18 @@ async def abort_job(id_job: int, user: nebula.User) -> None:
161169 )
162170
163171
172+ async def set_priority (id_job : int , priority : int , user : nebula .User ) -> None :
173+ if not await can_user_control_job (user , id_job ):
174+ raise nebula .ForbiddenException ("You cannot set priority of this job" )
175+ nebula .log .info (f"Setting priority of job { id_job } to { priority } " , user = user .name )
176+ query = """
177+ UPDATE jobs SET
178+ priority = $1
179+ WHERE id = $2
180+ """
181+ await nebula .db .execute (query , priority , id_job )
182+
183+
164184class JobsRequest (APIRequest ):
165185 """List and control jobs"""
166186
@@ -180,6 +200,9 @@ async def handle(
180200 if request .restart :
181201 await restart_job (request .restart , user )
182202
203+ if request .priority is not None :
204+ await set_priority (request .priority [0 ], request .priority [1 ], user )
205+
183206 # Return a list of jobs if requested
184207
185208 conds = []
@@ -223,6 +246,7 @@ async def handle(
223246 j.id_user AS id_user,
224247 j.status AS status,
225248 j.progress AS progress,
249+ j.priority AS priority,
226250 j.message AS message,
227251 j.creation_time AS ctime,
228252 j.start_time AS stime,
0 commit comments