def check(self):

        log.debug(
            "Scheduler checking for out-of-date scheduled tasks (%s scheduled)..." %
            len(
                self.all_tasks))
        for task in self.all_tasks:

            now = datetime.datetime.utcnow()
            interval = datetime.timedelta(seconds=task["interval"])

            last_time = now - interval

            if task.get("dailytime"):

                dailytime = task.get("dailytime").time()

                time_datelastqueued = task.get(
                    "datelastqueued").time().isoformat()[0:8]
                time_dailytime = dailytime.isoformat()[0:8]
                if task.get(
                        "datelastqueued") and time_datelastqueued != time_dailytime:
                    log.debug(
                        "Adjusting the time of scheduled task %s from %s to %s" %
                        (task["_id"], time_datelastqueued, time_dailytime))

                    # Make sure we don't queue the task in a loop by adjusting
                    # the time
                    if time_datelastqueued < time_dailytime:
                        adjusted_datelastqueued = datetime.datetime.combine(
                            task.get("datelastqueued").date() -
                            datetime.timedelta(days=1),
                            dailytime)
                    else:
                        adjusted_datelastqueued = datetime.datetime.combine(
                            task.get("datelastqueued").date(), dailytime)

                    # We do find_and_modify and not update() because several check()
                    # may be happening at the same time.
                    self.collection.find_and_modify(
                        {
                            "_id": task["_id"],
                            "datelastqueued": task.get("datelastqueued")
                        },
                        {"$set": {
                            "datelastqueued": adjusted_datelastqueued
                        }}
                    )
                    self.refresh()

            task_data = self.collection.find_and_modify(
                {
                    "_id": task["_id"],
                    "datelastqueued": {"$lt": last_time}
                },
                {"$set": {
                    "datelastqueued": now
                }}
            )

            if task_data:
                queue_job(
                    task_data["path"],
                    task_data["params"],
                    queue=task.get("queue"))
                log.debug("Scheduler: queued %s" % task_data)

                self.refresh()
dataset/ETHPy150Open pricingassistant/mrq/mrq/scheduler.py/Scheduler.check/original