MCPcopy Index your code
hub / github.com/diffgram/diffgram / get_task_from_job_id

Method get_task_from_job_id

shared/database/task/task.py:216–277  ·  view source on GitHub ↗
(
            session,
            job_id,
            user,
            direction = 'next',
            assign_to_user = False,
            skip_locked = True)

Source from the content-addressed store, hash-verified

214
215 @staticmethod
216 def get_task_from_job_id(
217 session,
218 job_id,
219 user,
220 direction = 'next',
221 assign_to_user = False,
222 skip_locked = True):
223 from methods.task.task.task_update import Task_Update
224 from sqlalchemy import union, join
225 # Query for tasks with status 'available'
226 query1 = (
227 session.query(Task)
228 .filter(sa.and_(Task.status == 'available', Task.job_id == job_id))
229 )
230
231 # Query for tasks with status 'in_progress' and assigned to the user
232 query2 = (
233 session.query(Task)
234 .join(TaskUser, Task.id == TaskUser.task_id)
235 .filter(
236 sa.and_(
237 Task.status == 'in_progress',
238 Task.job_id == job_id,
239 TaskUser.user_id == user.id,
240 )
241 )
242 )
243
244 # Combine the results using a union
245 combined_query = query1.union(query2).subquery().alias('task_union')
246
247 query = session.query(Task).select_entity_from(combined_query)
248
249 if direction == 'next':
250 query = query.order_by(Task.time_created)
251
252 elif direction == 'previous':
253 query = query.order_by(Task.time_created.desc())
254
255 if skip_locked == True:
256 # query = query.with_for_update(skip_locked = True)
257 pass
258 from sqlalchemy import create_engine, text
259 task = query.first()
260 if assign_to_user is True:
261
262 # TODO check if job has open status, or user is assigned to job
263 # For now this assumes that the user is already on correct job
264
265 if task:
266 task.add_assignee(session, user)
267 task_update_manager = Task_Update(
268 session = session,
269 task = task,
270 status = 'in_progress'
271 )
272 # set status
273 task_update_manager.main()

Callers 2

task_next_coreFunction · 0.80

Calls 4

mainMethod · 0.95
Task_UpdateClass · 0.90
add_assigneeMethod · 0.80
addMethod · 0.45

Tested by 1