from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import warner
import archiver
import announcer
import flagger
import os

logging.basicConfig()
sched = BlockingScheduler()

@sched.scheduled_job("cron", hour=4)
#@sched.scheduled_job("cron", hour="*", minute="*/10") # for testing
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        scheduled_warner = warner.Warner()
        scheduled_archiver = archiver.Archiver()
        scheduled_announcer = announcer.Announcer()
        scheduled_flagger = flagger.Flagger()
        print("Warning")
        scheduled_warner.warn()
        print("Archiving")
        scheduled_archiver.archive()
        print("Announcing")
        scheduled_announcer.announce()
        print("Flagging")
        scheduled_flagger.flag()
        print("OK: destalinated")
    print("END: destalinate_job")

sched.start()

from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import warner
import archiver
import announcer
import flagger
import os


# When testing changes, set the "TEST_SCHEDULE" envvar to run more often
if os.getenv("TEST_SCHEDULE"):
    schedule_kwargs = {"hour": "*", "minute": "*/10"}
else:
    schedule_kwargs = {"hour": 4}

logging.basicConfig()
sched = BlockingScheduler()

@sched.scheduled_job("cron", **schedule_kwargs)
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        scheduled_warner = warner.Warner()
        scheduled_archiver = archiver.Archiver()
        scheduled_announcer = announcer.Announcer()
        scheduled_flagger = flagger.Flagger()
        print("Warning")
        scheduled_warner.warn()
        print("Archiving")
        scheduled_archiver.archive()
        print("Announcing")
        scheduled_announcer.announce()
        print("Flagging")
        scheduled_flagger.flag()
        print("OK: destalinated")
    print("END: destalinate_job")

sched.start()

Switch to a test schedule based on the environment
Switch to a test schedule based on the environment

Switching an environment variable and kicking the `clock` process feels
like a neater solution than commenting out one line, uncommenting
another, and redeploying.

  from apscheduler.schedulers.blocking import BlockingScheduler
  import logging
  import warner
  import archiver
  import announcer
  import flagger
  import os
  
+ 
+ # When testing changes, set the "TEST_SCHEDULE" envvar to run more often
+ if os.getenv("TEST_SCHEDULE"):
+     schedule_kwargs = {"hour": "*", "minute": "*/10"}
+ else:
+     schedule_kwargs = {"hour": 4}
+ 
  logging.basicConfig()
  sched = BlockingScheduler()
  
- @sched.scheduled_job("cron", hour=4)
+ @sched.scheduled_job("cron", **schedule_kwargs)
- #@sched.scheduled_job("cron", hour="*", minute="*/10") # for testing
  def destalinate_job():
      print("Destalinating")
      if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
          print("ERR: Missing at least one Slack environment variable.")
      else:
          scheduled_warner = warner.Warner()
          scheduled_archiver = archiver.Archiver()
          scheduled_announcer = announcer.Announcer()
          scheduled_flagger = flagger.Flagger()
          print("Warning")
          scheduled_warner.warn()
          print("Archiving")
          scheduled_archiver.archive()
          print("Announcing")
          scheduled_announcer.announce()
          print("Flagging")
          scheduled_flagger.flag()
          print("OK: destalinated")
      print("END: destalinate_job")
  
  sched.start()
  
Switch to a test schedule based on the environment
## Code Before:
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import warner
import archiver
import announcer
import flagger
import os

logging.basicConfig()
sched = BlockingScheduler()

@sched.scheduled_job("cron", hour=4)
#@sched.scheduled_job("cron", hour="*", minute="*/10") # for testing
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        scheduled_warner = warner.Warner()
        scheduled_archiver = archiver.Archiver()
        scheduled_announcer = announcer.Announcer()
        scheduled_flagger = flagger.Flagger()
        print("Warning")
        scheduled_warner.warn()
        print("Archiving")
        scheduled_archiver.archive()
        print("Announcing")
        scheduled_announcer.announce()
        print("Flagging")
        scheduled_flagger.flag()
        print("OK: destalinated")
    print("END: destalinate_job")

sched.start()

## Instruction:
Switch to a test schedule based on the environment
## Code After:
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import warner
import archiver
import announcer
import flagger
import os


# When testing changes, set the "TEST_SCHEDULE" envvar to run more often
if os.getenv("TEST_SCHEDULE"):
    schedule_kwargs = {"hour": "*", "minute": "*/10"}
else:
    schedule_kwargs = {"hour": 4}

logging.basicConfig()
sched = BlockingScheduler()

@sched.scheduled_job("cron", **schedule_kwargs)
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        scheduled_warner = warner.Warner()
        scheduled_archiver = archiver.Archiver()
        scheduled_announcer = announcer.Announcer()
        scheduled_flagger = flagger.Flagger()
        print("Warning")
        scheduled_warner.warn()
        print("Archiving")
        scheduled_archiver.archive()
        print("Announcing")
        scheduled_announcer.announce()
        print("Flagging")
        scheduled_flagger.flag()
        print("OK: destalinated")
    print("END: destalinate_job")

sched.start()
