import remoulade from remoulade.scheduler import Scheduler, ScheduledJob from remoulade.brokers.rabbitmq import RabbitmqBroker broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) remoulade.set_scheduler( Scheduler(broker, [ ScheduledJob(actor_name="write_loaded_at", kwargs={ "filename": "/tmp/scheduler-2", "text": "simple schedule\n" }, interval=3600) ], period=0.1)) @remoulade.actor() def write_loaded_at(filename, text): with open(filename, "a+") as f: f.write(text) broker.declare_actor(write_loaded_at)
from remoulade.brokers.rabbitmq import RabbitmqBroker from remoulade.scheduler import ScheduledJob, Scheduler broker = RabbitmqBroker() remoulade.set_broker(broker) @remoulade.actor() def count_words(url): response = requests.get(url).text print("There are {} words in {}".format(len(response), url)) broker.declare_actor(count_words) if __name__ == "__main__": scheduler = Scheduler( broker, [ ScheduledJob(actor_name="count_words", kwargs={"url": "https://github.com"}, interval=1), ScheduledJob(actor_name="count_words", kwargs={"url": "https://gitlab.com"}, interval=10), ], period=0.1, # scheduler run each 0.1 (second) ) remoulade.set_scheduler(scheduler) scheduler.start()
from remoulade.brokers.rabbitmq import RabbitmqBroker from remoulade.scheduler import ScheduledJob, Scheduler broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) remoulade.set_scheduler( Scheduler( broker, [ ScheduledJob( actor_name="write_loaded_at", kwargs={ "filename": "/tmp/scheduler-1", "text": "simple schëdule\n" }, interval=1, ), ScheduledJob( actor_name="mul", kwargs={ "x": 1, "y": 2 }, interval=3600), ], period=0.1, )) @remoulade.actor() def write_loaded_at(filename, text): with open(filename, "a+") as f: f.write(text)
def new_scheduler(stub_broker): redis_url = os.getenv("REMOULADE_TEST_REDIS_URL") or "redis://localhost:6481/0" scheduler = Scheduler(stub_broker, [], period=0.1, url=redis_url) remoulade.set_scheduler(scheduler) return scheduler
import datetime import remoulade from remoulade.scheduler import Scheduler, ScheduledJob from remoulade.brokers.rabbitmq import RabbitmqBroker broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) remoulade.set_scheduler( Scheduler(broker, [ ScheduledJob( actor_name="write_loaded_at", kwargs={"filename": "/tmp/scheduler-weekday-1", "text": "simple schedule\n"}, iso_weekday=datetime.datetime.now().isoweekday() + 1 ) ], period=0.1) ) @remoulade.actor() def write_loaded_at(filename, text): with open(filename, "a+") as f: f.write(text) broker.declare_actor(write_loaded_at)
import pytz import remoulade from remoulade.scheduler import Scheduler, ScheduledJob from remoulade.brokers.rabbitmq import RabbitmqBroker broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) timezone = pytz.timezone("Europe/Paris") remoulade.set_scheduler( Scheduler(broker, [ ScheduledJob(actor_name="write_loaded_at", kwargs={ "filename": "/tmp/scheduler-daily_tz", "text": "simple schedule\n" }, daily_time=(datetime.datetime.now(timezone) + datetime.timedelta(seconds=5)).time(), tz="Europe/Paris") ], period=0.1)) @remoulade.actor() def write_loaded_at(filename, text): with open(filename, "a+") as f: f.write(text) broker.declare_actor(write_loaded_at)
import datetime import remoulade from remoulade.scheduler import Scheduler, ScheduledJob from remoulade.brokers.rabbitmq import RabbitmqBroker broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) remoulade.set_scheduler( Scheduler(broker, [ ScheduledJob( actor_name="write_loaded_at", kwargs={"filename": "/tmp/scheduler-daily-new", "text": "simple schedule\n"}, daily_time=(datetime.datetime.utcnow() - datetime.timedelta(seconds=60)).time() ) ], period=0.1) ) @remoulade.actor() def write_loaded_at(filename, text): with open(filename, "a+") as f: f.write(text) broker.declare_actor(write_loaded_at)
import remoulade from remoulade.brokers.rabbitmq import RabbitmqBroker from remoulade.scheduler import ScheduledJob, Scheduler broker = RabbitmqBroker(max_priority=10) remoulade.set_broker(broker) remoulade.set_scheduler( Scheduler( broker, [ ScheduledJob(actor_name="add", kwargs={ "x": 1, "y": 2 }, interval=1), ScheduledJob( actor_name="mul", kwargs={ "x": 1, "y": 2 }, interval=3600), ], period=0.1, )) @remoulade.actor() def add(x, y): return x + y @remoulade.actor() def mul(x, y):