aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine
diff options
context:
space:
mode:
authorjason2017-07-07 09:28:43 -0600
committerjason2017-07-07 09:28:43 -0600
commit9f2da02ef3eed799e50066d6fd6ea504adb1852d (patch)
tree09f3260acb6e4eaa617f94e2664fbce009d79334 /warmachine
parent2d87bd8b4e455b1f50e54820952928d766079463 (diff)
downloadwarmachine-ng-9f2da02ef3eed799e50066d6fd6ea504adb1852d.tar.gz
warmachine-ng-9f2da02ef3eed799e50066d6fd6ea504adb1852d.zip
Fix warmachine not honoring weekend
- The offset for the next job was being calucated by `timedelta.seconds` rather than `timedelta.total_seconds()`
Diffstat (limited to 'warmachine')
-rwxr-xr-xwarmachine/addons/standup.py26
-rwxr-xr-xwarmachine/connections/slack.py17
-rw-r--r--warmachine/utils/decorators.py8
3 files changed, 36 insertions, 15 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py
index 21d05e2..f4c3288 100755
--- a/warmachine/addons/standup.py
+++ b/warmachine/addons/standup.py
@@ -246,8 +246,14 @@ class StandUpPlugin(WarMachinePlugin):
246 """ 246 """
247 next_standup = self.get_next_standup_secs(time24h) 247 next_standup = self.get_next_standup_secs(time24h)
248 248
249 self.log.info('Scheduling standup on connection {} for channel {} @ '
250 '{}'.format(
251 connection.__class__.__name__, channel, next_standup))
252
253
254 # calculate the timedelta for next standup and now
249 standup_td = next_standup - datetime.now() 255 standup_td = next_standup - datetime.now()
250 next_standup_secs = standup_td.seconds 256 next_standup_secs = standup_td.total_seconds()
251 257
252 f = self._loop.call_later( 258 f = self._loop.call_later(
253 next_standup_secs, functools.partial( 259 next_standup_secs, functools.partial(
@@ -258,19 +264,16 @@ class StandUpPlugin(WarMachinePlugin):
258 self.standup_schedules[channel]['future'].cancel() 264 self.standup_schedules[channel]['future'].cancel()
259 265
260 self.standup_schedules[channel]['future'] = f 266 self.standup_schedules[channel]['future'] = f
261 self.standup_schedules[channel]['datetime'] = next_standup 267 self.standup_schedules[channel]['next_standup'] = next_standup
262 self.standup_schedules[channel]['time24h'] = time24h 268 self.standup_schedules[channel]['time24h'] = time24h
263 else: 269 else:
264 self.standup_schedules[channel] = { 270 self.standup_schedules[channel] = {
265 'future': f, 271 'future': f,
266 'datetime': next_standup, 272 'next_standup': next_standup,
267 'time24h': time24h, 273 'time24h': time24h,
268 'ignoring': [], 274 'ignoring': [],
269 } 275 }
270 276
271 self.log.info('New schedule added to channel {} for {}'.format(
272 channel, time24h))
273
274 def standup_schedule_func(self, connection, channel): 277 def standup_schedule_func(self, connection, channel):
275 """ 278 """
276 Non-async function used to schedule the standup for a channel. 279 Non-async function used to schedule the standup for a channel.
@@ -420,12 +423,13 @@ class StandUpPlugin(WarMachinePlugin):
420 423
421 standup_hour, standup_minute = (int(s) for s in time24h.split(':')) 424 standup_hour, standup_minute = (int(s) for s in time24h.split(':'))
422 425
423 next_standup = datetime(now.year, now.month, now.day, 426 next_standup = datetime(
424 standup_hour, standup_minute) 427 now.year, now.month, now.day, standup_hour, standup_minute)
425 428
426 # If we've already past the time for today, schedule it for that time 429 # Schedule for the future if:
427 # on the next weekday 430 # - we've already past the time for today
428 if now > next_standup or now.isoweekday() > 4: 431 # - it's a weekend
432 if now >= next_standup or now.isoweekday() > 5:
429 # if it's friday(5), wait 72 hours 433 # if it's friday(5), wait 72 hours
430 if now.isoweekday() == 5: 434 if now.isoweekday() == 5:
431 hours = 72 435 hours = 72
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py
index 7585c74..eaa1395 100755
--- a/warmachine/connections/slack.py
+++ b/warmachine/connections/slack.py
@@ -542,3 +542,20 @@ class SlackWS(Connection):
542 # 'avatar_hash': '49ec8bc36896'}, 542 # 'avatar_hash': '49ec8bc36896'},
543 # 'subtype': 'group_join', 543 # 'subtype': 'group_join',
544 # 'text': '<@U0286167T|synic> has joined the group'} 544 # 'text': '<@U0286167T|synic> has joined the group'}
545
546 def on_desktop_notification(self, msg):
547 """
548 Desktop notifications, I guess
549 """
550 # {'subtitle': 'jason',
551 # 'content': '!standup-add 16:35',
552 # 'channel': 'D22S9KBG9',
553 # 'title': 'Teem',
554 # 'ssbFilename': 'knock_brush.mp3',
555 # 'is_shared': False,
556 # 'msg': '1499294083.080598',
557 # 'avatarImage': 'https://avatars.sla....._72.jpg',
558 # 'event_ts': '1499294083.293788',
559 # 'launchUri': 'slack://channel?id=D2.....&team=T027XPE12',
560 # 'type': 'desktop_notification',
561 # 'imageUri': None}
diff --git a/warmachine/utils/decorators.py b/warmachine/utils/decorators.py
index e049e79..ffe7306 100644
--- a/warmachine/utils/decorators.py
+++ b/warmachine/utils/decorators.py
@@ -25,12 +25,12 @@ class memoize(object):
25 25
26 h = self._hash(str(args) + str(kwargs)) 26 h = self._hash(str(args) + str(kwargs))
27 if h in self.cache: 27 if h in self.cache:
28 self.log.debug('Using cached value for {}({}, {})'.format( 28 # This is noisy, but helpful for debugging so it's commented out
29 self.func.__name__, ', '.join(str(a) for a in args), 29 # self.log.debug('Using cached value for {}({}, {})'.format(
30 ','.join('{}={} '.format(k, v) for k, v in kwargs.items()))) 30 # self.func.__name__, ', '.join(str(a) for a in args),
31 # ','.join('{}={} '.format(k, v) for k, v in kwargs.items())))
31 return self.cache[h] 32 return self.cache[h]
32 else: 33 else:
33 self.log.debug('Caching value')
34 value = self.func(*args, **kwargs) 34 value = self.func(*args, **kwargs)
35 self.cache[h] = value 35 self.cache[h] = value
36 36