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

9 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-07-22 17:19 +0000

1""" 

2Background jobs 

3""" 

4 

5import logging 

6 

7from couchers.db import session_scope 

8from couchers.models import BackgroundJob 

9 

10logger = logging.getLogger(__name__) 

11 

12 

13def queue_job(job_type: str, 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