Beispiel #1
0
def handle_set_ms(msg, value):
    """
    Handles an incoming 'set_<on/off>_ms' MQTT message.
    :param msg: The incoming MQTT message
    :type msg: paho.mqtt.client.MQTTMessage
    :param value: The value to set the output to
    :type value: bool
    :return: None
    :rtype: NoneType
    """
    try:
        ms = int(msg.payload)
    except ValueError:
        raise InvalidPayload(
            "Could not parse ms value %r to an integer." % msg.payload)
    suffix = SET_ON_MS_TOPIC if value else SET_OFF_MS_TOPIC
    output_name = output_name_from_topic(msg.topic, topic_prefix, suffix)
    output_config = output_by_name(output_name)
    if output_config is None:
        return

    set_state(output_config, value)
    scheduler.add_task(Task(
        time() + ms/1000.0,
        set_state,
        output_config,
        not value
    ))
    _LOG.info(
        "Scheduled output %r to change back to %r after %r ms.",
        output_config["name"],
        not value,
        ms
    )
Beispiel #2
0
 def save_query(self, query):
     self.scheduler.schedule_task(
         Task(lambda: self.query_storage.append(
             query, default=RedditQueryListing()),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.APPEND_QUERY,
              id=query.id))
Beispiel #3
0
 def send_email_notification(self, query, posts):
     user = self.user_storage.read_all(User())
     email = RedditEmail(self.emailer.client.email, user.email)
     email.create_message(query, posts)
     self.scheduler.schedule_task(
         Task(lambda: self.emailer.send(email),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.EMAIL_QUERY_RESULT))
Beispiel #4
0
    def __init__(self, dodo_path, doit_task, base_path=None, timeout=None):
        Task.__init__(self)
        self.dodo_path = dodo_path
        self.base_path = base_path if base_path else os.path.dirname(dodo_path)
        self.doit_task = doit_task
        self.timeout = timeout
        # key: task/job name
        # value: list of results (dict)
        self.final_result = {}

        self.result_file = "%s/result.json" % self.base_path
        self.run_options = [
            ("--file", self.dodo_path),
            ("--reporter", "json"),
            ("--output-file", self.result_file),
            ("--dir", self.base_path),
        ]
Beispiel #5
0
 def search_reddit(self, querylisting):
     for id, query in querylisting.listing.items():
         self.scheduler.schedule_task(
             Task(lambda: self.reddit.query(query),
                  trigger=TaskTrigger.INTERVAL,
                  name=TaskName.QUERY_REDDIT,
                  id=query.id,
                  trigger_args={Time.MIN: 1}))
Beispiel #6
0
class Leet:
    @scheduled(Task.every().day.at("13:37"))
    def l33t(self):
        for servername, server in self.bot.servers.items():
            for channel in server.channels:
                self.bot.send(
                    Message(server=servername,
                            params=channel,
                            command="PRIVMSG",
                            text="LEET TIME"))
Beispiel #7
0
def test_task_init(task_init):
    task2 = Task()
    assert task_init['id'] == 1
    assert task_init['s_time'] == '7:00'
    assert task_init['e_time'] == '8:00'
    assert task_init['title'] == 'have breakfast'
    assert task_init['content'] == 'tomato,milk,bread'
    assert task_init['level'] == 5
    assert task_init['percent'] == 0.85
    assert task_init['users'] == {'qxc', 'daidai'}
    assert task2['id'] == 2
    print(task_init, task2)
Beispiel #8
0
class testing2:
    @command("argtest", groups="(.)(.*)")
    def argtest(self, message):
        return message.reply(str(message.groups))

    @command("test")
    def test(self, message):
        yield message.reply("your message: " + str(message))
        yield message.reply("your message: " + str(message))

    @command("data")
    def data(self, message):
        return message.reply("your message's data is: " +
                             repr(str(message.data)))

    @regex("^<(.*?)>$")
    def regextest(self, message):
        return message.reply(message.groups)

    @command("admin", adminonly=True)
    def admin(self, message):
        return message.reply("yes {}, you are an admin!".format(message.nick))

    @scheduled(Task.every(1).minute)
    def oneminute(self):
        self.bot.send(
            Message(server="Holmes",
                    params="#piperbot",
                    command="PRIVMSG",
                    text="1 min"))

    @adv_command("time")
    def timer(self, arg, target):
        start = time.perf_counter()
        try:
            while 1:
                x = yield
        except GeneratorExit:
            total = time.perf_counter() - start
            target.send(arg.reply(total, "took %s seconds" % total))
            target.close()
Beispiel #9
0
def cmd_sched(server: AppServer, args):
    app = server._clients
    clients = server._clients._clients
    if args[0].lower() == "add":
        tt = time.time()
        arr, args = parse_args(
            args[1:], {
                "clients": (["-c", "--client"], None),
                "interval": (["-i", "--interval"], -1),
                "start": (["-s", "--start"], time.time()),
                "repeat": (["-r", "--repeat"], -1)
            })
        print("-------->", (time.time() - tt) * 1000)
        c = args["clients"]
        if not c:
            c = []
            for k in clients:
                c.append(k)

        t = Task.interval(c, Command.from_args(arr[0], arr[1:]),
                          float(args["start"]), float(args["interval"]),
                          float(args["repeat"]))
        server._clients.get_scheduler().add_task(t)
    return CommandReturn(0, "")
Beispiel #10
0
def task_init():
    arg = ('7:00', '8:00', 'have breakfast', 'tomato,milk,bread', 5, 0.85,
        {'qxc', 'daidai'})
    return Task(*arg)
Beispiel #11
0
 def get_task(self):
     self.task = Task()
     self.task.start_date = self.due_time.date()
     self.task.start_time = self.due_time.time()
     return self.task
Beispiel #12
0
 def save_user(self, user):
     self.scheduler.schedule_task(
         Task(lambda: self.user_storage.overwrite(user),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.OVERWRITE_USER))
Beispiel #13
0
 def delete_from_storage(self, id):
     self.scheduler.schedule_task(
         Task(lambda: self.query_storage.delete(id, RedditQueryListing()),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.DELETE_QUERY))
Beispiel #14
0
 def update_storage(self, id, query):
     self.scheduler.schedule_task(
         Task(lambda: self.query_storage.update(id, query,
                                                RedditQueryListing()),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.UPDATE_QUERY))
Beispiel #15
0
#!/usr/bin/env python
from scheduler import Task, TaskGroup

tasks = TaskGroup()
tasks.add_task(Task("test 1", "9:44 AM", "CALL my_proc_1()"))
tasks.add_task(Task("test 2", "2:30 PM", "CALL my_proc_2()"))
tasks.save_tasks("data/tasks.json")

# show the contents of the task json file created by the above
with open('data/tasks.json', 'r') as f:
    for line in f:
        print line,
Beispiel #16
0
 def get_query_by_id(self, id):
     self.scheduler.schedule_task(
         Task(lambda: self.query_storage.read_by_key(id),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.READ_QUERY))
Beispiel #17
0
 def get_querylisting(self):
     self.scheduler.schedule_task(
         Task(lambda: self.query_storage.read_all(default=
                                                  RedditQueryListing()),
              trigger=TaskTrigger.ONE_OFF,
              name=TaskName.READ_QUERYLISTING))
 def schedule_single_task(self):
     self.scheduler = TaskScheduler(QtScheduler())
     self.task = Task(test_func)
     self.scheduledTask = self.scheduler.schedule_task_in_interval(
         self.task, 1, Time.SEC)