def main(): scheduler = Scheduler() servermap = ServerMap() scheduler.add_job(servermap.reload, trigger='cron', minute='*/5') scheduler.add_job(servermap.main, trigger='cron', minute='*/1') scheduler.start() dashboard.run()
def __init__(self, name): """ Init things. :param name: str: name """ self.name = name self.scheduler = Scheduler() self.keep = True # class attribute or instance attribute self.father, self.child = Pipe()
def __init__(self, name, queue): """ Init things. :param name: str: name :param queue: multiprocessing.Queue """ self.name = name self.scheduler = Scheduler() self.keep = True # class attribute or instance attribute self.queue = queue
def __init__(self): """Webex Teams notification bot for the RCSS Graveyard Team Intended to notify agents on an hourly basis on the 9agent's schedule to remind them to send an email to their managers. Usage: Just run the hermes.py to start the bot locally, then look for it on Webex Teams, either with the name: HermessRCSS or with the full name: [email protected]\n After that, send the '/subscribe' command to set up the notification times. """ self.clear_screen() self.current_user = None # Define current interacting user self.filepath = "peopletonotify.json" # Define where to find the users file self.baseurl = "https://api.ciscospark.com/v1" # API vars # Retrieve required details from environment variables dotenv.load_dotenv() # Open a HTTP tunnel on the default port 8080 self.start_local_server() # Get enviroment details self.bot_email = os.getenv("TEAMS_BOT_EMAIL") self.teams_token = os.getenv("TEAMS_BOT_TOKEN") self.bot_app_name = os.getenv("TEAMS_BOT_APP_NAME") self.api = WebexTeamsAPI(access_token=self.teams_token) # Start API # Create the Bot Object self.bot = webexteamsbot.TeamsBot( self.bot_app_name, teams_bot_token=self.teams_token, teams_bot_url=self.bot_url, teams_bot_email=self.bot_email, webhook_resource_event=[ { "resource": "messages", "event": "created" }, # Handles Messages { "resource": "attachmentActions", "event": "created" } ]) # Handles Adaptive cards self.bot.set_help_message( "Hello, my name is Hermes! You can use the following commands:\n") self.add_commands() self.init_users_file() # Create the scheduler self.sched = Scheduler({'apscheduler.timezone': 'America/Costa_Rica'}) self.sched.remove_all_jobs() self.sched.start() # Start the scheduler self.schedule_subscriptions() self.bot.run(host="localhost", port=8080) # Run Bot
from django.contrib.auth.models import User from django.db import models # Create your models here. from django.db.models.signals import post_save from django.dispatch import receiver from apscheduler.schedulers.background import BackgroundScheduler as Scheduler from django.core.mail import send_mail from datetime import datetime, timedelta # Start the scheduler sched = Scheduler() sched.start() # Define the function that is to be executed def my_job(): print("payment verification...") users = User.objects.all() today = datetime.today() emails = list() for user in users: if user.date_joined.day == today.day and user.date_joined.month != today.month: user.date_joined = today user.save() emails.append(user.username) print(emails) if emails: send_mail(
import threading as T #from apscheduler.schedulers.blocking import BlockingScheduler as Scheduler from apscheduler.schedulers.background import BackgroundScheduler as Scheduler from apscheduler.executors.pool import ThreadPoolExecutor from time import sleep executors = {'default': ThreadPoolExecutor(3)} s = Scheduler(executors=executors) def show(msg='a'): print '--------------------', msg for t in T.enumerate(): print t def output(): print '.' def close(time = 5): sleep(time) show("closing") s.shutdown() show("closed") s.add_job(output, 'interval', seconds=1) s.start() t = T.Thread(target=close, name="close") t.start() #for i in range(6): while True: sleep(1)
# coding:utf-8 import threading as T import logging from time import sleep from apscheduler.schedulers.background import BackgroundScheduler as Scheduler logging.basicConfig() s = Scheduler() mutex = T.Lock() def show(name, l): if mutex.acquire(1): for i in l: print i, sleep(2) print 'name is', name mutex.release() def f1(): show(1, ['1'] * 7) def f2(): show(2, ['2'] * 7) def f3():
return make_json_respond(controllers[plant_id].led_power)(status) def init_controllers(): my_list = [ PlantController(plant_id=0, device_name="/dev/ttyUSB0"), PlantController(plant_id=1, device_name="/dev/ttyUSB1"), PlantController(plant_id=2, device_name="/dev/ttyUSB2"), PlantController(plant_id=3, device_name="/dev/ttyUSB3"), PlantController(plant_id=4, device_name="/dev/ttyUSB4"), PlantController(plant_id=5, device_name="/dev/ttyUSB5"), PlantController(plant_id=6, device_name="/dev/ttyUSB6"), PlantController(plant_id=7, device_name="/dev/ttyUSB7"), PlantController(plant_id=8, device_name="/dev/ttyUSB8"), PlantController(plant_id=9, device_name="/dev/ttyUSB9") ] return my_list if __name__ == '__main__': controllers = init_controllers() scheduler = Scheduler() scheduler.add_job(controllers[0].get_temperature, trigger='interval', args=[1], seconds=5) scheduler.start() app.run(host='0.0.0.0')
def mainjob(self, name): self.filename = '/tmp/dc/django_celery_%s.log' % name # prepare out_output(str(self.request.retries), self.filename) self.default_retry_delay = 5 self.max_retries = 2 self.count = 0 # reply_to = self.request.reply_to # out_output(reply_to, self.filename) # out_output(dir(reply_to), self.filename) # out_output(reply_to.__doc__, self.filename) # out_output(type(reply_to), self.filename) jlogger = logging.getLogger('apscheduler.scheduler') jlogger.setLevel(logging.ERROR) scheduler = Scheduler(logger=jlogger) self.update_state(state='RUNNING') # shutdown def shutdown(a, b): output('shuting') scheduler.shutdown() output('down - %s' % time()) def terminate(a, b): output('terminating') scheduler.shutdown() output('down - %s' % time()) def retryer(a, b): out_output('before retry', self.filename) scheduler.shutdown() raise self.retry() out_output('after retry', self.filename) signal(SIGUSR1, shutdown) signal(SIGTERM, terminate) signal(SIGALRM, retryer) # listen def listener(event): try: raise event.exception except Exception as e: out_output(e, self.filename) [job.pause() for job in scheduler.get_jobs()] alarm(1) scheduler.add_listener(listener, EVENT_JOB_ERROR) # add job and start def output(msg): self.count += 1 #if self.count == 9: raise StandardError('haha') with open(self.filename, 'a') as file: file.write('(%s - %s) %s\n' % (time(), name, msg)) scheduler.add_job(output, 'interval', args=('--a',), seconds=1) sleep(0.5) scheduler.add_job(output, 'interval', args=('------b',), seconds=1) #scheduler.add_job(output, 'interval', args=('--b',), seconds=3) scheduler.start() # wait for retry pause()