Coverage for functions \ flipdare \ job \ app_job_schedule.py: 93%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14from datetime import datetime 

15from enum import Enum 

16 

17from flipdare.util.time_util import TimeUtil 

18 

19 

20class AppJobSchedule(Enum): 

21 """Job execution intervals""" 

22 

23 TWO_MINUTES = "2 minutes" 

24 FIVE_MINUTES = "5 minutes" 

25 FIFTEEN_MINUTES = "15 minutes" 

26 ONE_HOUR = "1 hour" 

27 TWO_HOURS = "2 hours" 

28 FOUR_HOURS = "4 hours" 

29 SIX_HOURS = "6 hours" 

30 TWELVE_HOURS = "12 hours" 

31 ONE_DAY = "1 day" 

32 THREE_DAYS = "3 days" 

33 ONE_WEEK = "7 days" 

34 

35 @staticmethod 

36 def from_string(value: str) -> "AppJobSchedule": 

37 try: 

38 return AppJobSchedule(value.lower()) 

39 except ValueError as ve: 

40 raise ValueError(f"Invalid AppJobSchedule: {value}") from ve 

41 except AttributeError as ae: 

42 raise ValueError(f"Invalid AppJobSchedule: {value}") from ae 

43 

44 @property 

45 def get_minutes_ago(self) -> datetime: 

46 mapping = { 

47 AppJobSchedule.TWO_MINUTES: 2, 

48 AppJobSchedule.FIVE_MINUTES: 5, 

49 AppJobSchedule.FIFTEEN_MINUTES: 15, 

50 AppJobSchedule.ONE_HOUR: 60, 

51 AppJobSchedule.TWO_HOURS: 120, 

52 AppJobSchedule.FOUR_HOURS: 240, 

53 AppJobSchedule.SIX_HOURS: 360, 

54 AppJobSchedule.TWELVE_HOURS: 720, 

55 AppJobSchedule.ONE_DAY: 1440, 

56 AppJobSchedule.THREE_DAYS: 4320, 

57 AppJobSchedule.ONE_WEEK: 10080, 

58 } 

59 minutes = mapping.get(self, 1) 

60 return TimeUtil.get_utc_time_minutes_ago(minutes)