Пример #1
0
 def __init__(self,
              week_day,
              use_task_execution_day=False,
              *args,
              **kwargs):
     super(DayOfWeekSensor, self).__init__(*args, **kwargs)
     self.week_day = week_day
     self.use_task_execution_day = use_task_execution_day
     if isinstance(self.week_day, six.string_types):
         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, six.string_types) 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)))
Пример #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
Пример #3
0
 def __init__(self, week_day,
              use_task_execution_day=False,
              *args, **kwargs):
     super(DayOfWeekSensor, self).__init__(*args, **kwargs)
     self.week_day = week_day
     self.use_task_execution_day = use_task_execution_day
     if isinstance(self.week_day, six.string_types):
         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, six.string_types) 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)))
Пример #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)
Пример #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):
         e = WeekDay(i)
         self.assertEqual(e, i)
         self.assertEqual(int(e), i)
         self.assertEqual(e.name, weekday)
         self.assertTrue(e in WeekDay)
         self.assertTrue(0 < e < 8)
         self.assertTrue(type(e) is WeekDay)
         self.assertTrue(isinstance(e, int))
         self.assertTrue(isinstance(e, Enum))