Coverage for src/couchers/jobs/enqueue.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

9 statements  

1""" 

2Background jobs 

3""" 

4 

5import logging 

6 

7from couchers.db import session_scope 

8from couchers.models import BackgroundJob, BackgroundJobType 

9 

10logger = logging.getLogger(__name__) 

11 

12 

13def queue_job(job_type: BackgroundJobType, payload, max_tries=None): 

14 with session_scope() as session: 

15 job = BackgroundJob( 

16 job_type=job_type, 

17 payload=payload.SerializeToString(), 

18 max_tries=max_tries, 

19 ) 

20 session.add(job) 

21 return job.id