Exemplo n.º 1
0
    def __init__(
        self,
        *,
        follow_task_ids_if_true: Union[str, Iterable[str]],
        follow_task_ids_if_false: Union[str, Iterable[str]],
        week_day: Union[str, Iterable[str]],
        use_task_execution_day: bool = False,
        **kwargs,
    ) -> None:
        super().__init__(**kwargs)
        self.follow_task_ids_if_true = follow_task_ids_if_true
        self.follow_task_ids_if_false = follow_task_ids_if_false
        self.week_day = week_day
        self.use_task_execution_day = use_task_execution_day
        self._week_day_num = None

        if isinstance(self.week_day, str):
            self._week_day_num = {
                WeekDay.get_weekday_number(week_day_str=self.week_day)
            }
        elif isinstance(self.week_day, WeekDay):
            self._week_day_num = {self.week_day}
        elif isinstance(self.week_day, set):
            if all(isinstance(day, str) for day in self.week_day):
                self._week_day_num = {
                    WeekDay.get_weekday_number(day)
                    for day in week_day
                }
            elif all(isinstance(day, WeekDay) for day in self.week_day):
                self._week_day_num = self.week_day
        else:
            raise TypeError(
                'Unsupported Type for week_day parameter: {}. It should be one of str'
                ', set or Weekday enum type'.format(type(week_day)))
Exemplo n.º 2
0
 def poke(self, context):
     self.log.info('Poking until weekday is in %s, Today is %s',
                   self.week_day,
                   WeekDay(timezone.utcnow().isoweekday()).name)
     if self.use_task_execution_day:
         return context['execution_date'].isoweekday() in self._week_day_num
     else:
         return timezone.utcnow().isoweekday() in self._week_day_num
Exemplo n.º 3
0
 def __init__(self, week_day,
              use_task_execution_day=False,
              *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.week_day = week_day
     self.use_task_execution_day = use_task_execution_day
     if isinstance(self.week_day, str):
         self._week_day_num = {WeekDay.get_weekday_number(week_day_str=self.week_day)}
     elif isinstance(self.week_day, WeekDay):
         self._week_day_num = {self.week_day}
     elif isinstance(self.week_day, set):
         if all(isinstance(day, str) for day in self.week_day):
             self._week_day_num = {WeekDay.get_weekday_number(day) for day in week_day}
         elif all(isinstance(day, WeekDay) for day in self.week_day):
             self._week_day_num = self.week_day
     else:
         raise TypeError(
             'Unsupported Type for week_day parameter: {}. It should be one of str'
             ', set or Weekday enum type'.format(type(week_day)))
Exemplo n.º 4
0
 def test_weekday_name_value(self):
     weekdays = "MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY"
     weekdays = weekdays.split()
     for i, weekday in enumerate(weekdays, start=1):
         weekday_enum = WeekDay(i)
         self.assertEqual(weekday_enum, i)
         self.assertEqual(int(weekday_enum), i)
         self.assertEqual(weekday_enum.name, weekday)
         self.assertTrue(weekday_enum in WeekDay)
         self.assertTrue(0 < weekday_enum < 8)
         self.assertIsInstance(weekday_enum, WeekDay)
         self.assertIsInstance(weekday_enum, int)
         self.assertIsInstance(weekday_enum, Enum)
Exemplo n.º 5
0
 def test_weekday_name_value(self):
     weekdays = "MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY"
     weekdays = weekdays.split()
     for i, weekday in enumerate(weekdays, start=1):
         weekday_enum = WeekDay(i)
         assert weekday_enum == i
         assert int(weekday_enum) == i
         assert weekday_enum.name == weekday
         assert weekday_enum in WeekDay
         assert 0 < weekday_enum < 8
         assert isinstance(weekday_enum, WeekDay)
         assert isinstance(weekday_enum, int)
         assert isinstance(weekday_enum, Enum)
Exemplo n.º 6
0
 def __init__(
     self,
     *,
     follow_task_ids_if_true: Union[str, Iterable[str]],
     follow_task_ids_if_false: Union[str, Iterable[str]],
     week_day: Union[str, Iterable[str]],
     use_task_execution_day: bool = False,
     **kwargs,
 ) -> None:
     super().__init__(**kwargs)
     self.follow_task_ids_if_true = follow_task_ids_if_true
     self.follow_task_ids_if_false = follow_task_ids_if_false
     self.week_day = week_day
     self.use_task_execution_day = use_task_execution_day
     self._week_day_num = WeekDay.validate_week_day(week_day)
Exemplo n.º 7
0
 def __init__(self,
              *,
              week_day,
              use_task_logical_date=False,
              use_task_execution_day=False,
              **kwargs):
     super().__init__(**kwargs)
     self.week_day = week_day
     self.use_task_logical_date = use_task_logical_date
     if use_task_execution_day:
         self.use_task_logical_date = use_task_execution_day
         warnings.warn(
             "Parameter ``use_task_execution_day`` is deprecated. Use ``use_task_logical_date``.",
             DeprecationWarning,
             stacklevel=2,
         )
     self._week_day_num = WeekDay.validate_week_day(week_day)
Exemplo n.º 8
0
 def __init__(
     self,
     *,
     follow_task_ids_if_true: Union[str, Iterable[str]],
     follow_task_ids_if_false: Union[str, Iterable[str]],
     week_day: Union[str, Iterable[str]],
     use_task_logical_date: bool = False,
     use_task_execution_day: bool = False,
     **kwargs,
 ) -> None:
     super().__init__(**kwargs)
     self.follow_task_ids_if_true = follow_task_ids_if_true
     self.follow_task_ids_if_false = follow_task_ids_if_false
     self.week_day = week_day
     self.use_task_logical_date = use_task_logical_date
     if use_task_execution_day:
         self.use_task_logical_date = use_task_execution_day
         warnings.warn(
             "Parameter ``use_task_execution_day`` is deprecated. Use ``use_task_logical_date``.",
             DeprecationWarning,
             stacklevel=2,
         )
     self._week_day_num = WeekDay.validate_week_day(week_day)
Exemplo n.º 9
0
 def __init__(self, *, week_day, use_task_execution_day=False, **kwargs):
     super().__init__(**kwargs)
     self.week_day = week_day
     self.use_task_execution_day = use_task_execution_day
     self._week_day_num = WeekDay.validate_week_day(week_day)