Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 03 13:33
    Tesla-lu commented #511
  • May 03 13:28
    agronholm labeled #511
  • May 03 13:28
    agronholm closed #511
  • May 03 13:28
    agronholm commented #511
  • May 03 13:23
    Tesla-lu opened #511
  • May 02 12:25
    agronholm labeled #510
  • May 02 12:25
    agronholm closed #510
  • May 02 12:25
    agronholm commented #510
  • Apr 30 18:30
    caffeinatedMike opened #510
  • Apr 29 16:12
    huangsam commented #465
  • Apr 29 16:11
    huangsam commented #285
  • Apr 23 21:16
    mdz edited #509
  • Apr 22 17:30
    mdz opened #509
  • Apr 22 17:30
    mdz labeled #509
  • Apr 22 13:25
    agronholm commented #508
  • Apr 22 05:20
    alegend4u labeled #508
  • Apr 22 05:20
    alegend4u opened #508
  • Apr 16 12:45
    abood91 synchronize #505
  • Apr 15 08:29
    agronholm commented #507
  • Apr 15 00:56
    EvilMegaDroid closed #507
Omer Katz
@thedrow
I'm working on it now
Alex Grönholm
@agronholm
no, not yet
Omer Katz
@thedrow
I just need the async scheduler
Alex Grönholm
@agronholm
I expect to push a commit this week with appropriate changes
you don't want it in the state it's in now on my laptop
Omer Katz
@thedrow
Do you accept interval=0?
Alex Grönholm
@agronholm
no?
why
Omer Katz
@thedrow
Because I was wondering if I can run something in a loop using APScheduler.
Omer Katz
@thedrow
Maybe there could be a LoopInterval which just calls the task after it is done again
Alex Grönholm
@agronholm
@thedrow what is the point of using a scheduler for that?
Omer Katz
@thedrow
I have periodic tasks and continious tasks.
I'd like to use the same code path
Alex Grönholm
@agronholm
you could just add a job without a schedule (you can do that with apscheduler 4.0)
and in the code, make a while True: loop
interval=0 doesn't make sense because it would spawn an endless number of jobs, choking your machine
Omer Katz
@thedrow
so just scheduler.add_job?
Alex Grönholm
@agronholm
I think I made it so you can just omit the trigger if you want to queue a one-off task
(in v4.0)
sdementen
@sdementen
Hello @agronholm , i just discovered http://www.grantjenks.com/docs/diskcache/ that is a persistent cache on disk that is multi-thread and multi-process safe and can be used for IPC. Maybe useful for your project...
Alex Grönholm
@agronholm
@sdementen how would it be useful? I don't do caching in apscheduler.
sdementen
@sdementen
As a job store... But I remember the issue with multiple processes/threads was more on syncing to job store changes. Sorry for the "noise" ;-)
Omer Katz
@thedrow
Thank you! Thank you! I need this badly!
Omer Katz
@thedrow
It's blocking unfortunately
sdementen
@sdementen
@thedrow writes are blocking but you can shard (not sure if it scales for your needs though)
Omer Katz
@thedrow
If I can make a few changes and use rqlite instead that be swell!
Alex Grönholm
@agronholm
All file access is blocking by nature. I'll see if I can use it for synchronization somehow.
Christopher Pickering
@christopherpickering

Is there a way to generate a simulated schedule of jobs that will be running in the next few days? Currently if I just do "get jobs" It only show the next run, not the planned runs.

For a very basic example, if I have a job (job 1) that is scheduled on a 1 hour interval, I would get a list that shows all the times that we plan to run this job.

Name Schedule
Job 1 1:00PM
Job 1 2:00PM
Job 1 3:00PM
Job 1 4:00PM
Job 1 5:00PM
Job 1 6:00PM
Maybe there is some logic I can use based on how you are already interpreting the cron/interval/oneoff?

Alex Grönholm
@agronholm
@christopherpickering you can instantiate the trigger yourself and call get_next_fire_time() as many times as necessary
Alex Grönholm
@agronholm
you need to give the previously generated fire time as a parameter to the next call
in v4.0, triggers will be stateful so the procedure will be a bit different there
Christopher Pickering
@christopherpickering
awesome thanks!
hydrobeam
@hydrobeam
is there a way to pass custom data into a jobstore when creating a job with add_job? im using mongodb and would like to add more information about the scheduled task in my document
Alex Grönholm
@agronholm
@hydrobeam there isn't – the job store is supposed to be a black box
Tjeerd Bakker
@I_Cheered_gitlab
Hi, I'm having trouble with actually storing the jobs in a persistent database (RethinkgDB). Is there more I must do than adding the client handler to the jobstore, add the jobstore to the scheduler, and then just calling scheduler.add_job(<job>)?
databasename = "apscheduler"
tablename = "jobs"

r = RethinkDB()
connection = r.connect(host="localhost", port=28015, db=databasename)

jobstore = RethinkDBJobStore(database=databasename, table=tablename, client=connection)
executer = AsyncIOExecutor()
scheduler = AsyncIOScheduler(jobstore=jobstore, executer=executer)

stored_jobs = r.table(tablename).run(connection) # Returns []
job = scheduler.add_job(func=testfunc, trigger='interval', seconds=1, id="tst", name="TestJob", misfire_grace_time=None, replace_existing=True)
stored_jobs = r.table(tablename).run(connection) # Again returns []

connection.close()
Alex Grönholm
@agronholm
@I_Cheered_gitlab the schedulers arguments are wrong, they do nothing
Tjeerd Bakker
@I_Cheered_gitlab
Yeah I was confused by that because over there they add multiple job stores. When looking at documentation for AsyncIO Scheduler it says it inherits from the BaseScheduler, which has as parameters "jobstores (dict) – a dictionary of job store alias -> job store instance or configuration dict"... Does this mean that for a single jobstore I also make a dictionary with a single entry?
If I change it to the following (as per the example), the job is still not added to the database. The job itself is correct though, when calling scheduler.start() it will correctly start the async coroutine.
jobstore = RethinkDBJobStore(database=databasename, table=tablename, client=connection)
executer = AsyncIOExecutor()

jobstores = {
    'default': jobstore
}
executors = {
    'default': executer
}

scheduler = AsyncIOScheduler(jobstores=jobstores, executors=executors)
job = scheduler.add_job(func=testfunc, trigger='interval', seconds=1, id="tst", name="TestJob", misfire_grace_time=None, replace_existing=True)
stored_jobs = r.table(tablename).run(connection) # Still returns []
Tjeerd Bakker
@I_Cheered_gitlab
Aha I fixed it, the jobs aren't actually stored until scheduler.start() is called... I don't think this is in the documentation (yet? ;) ). Thanks for responding anyways @agronholm ! Really cool to see a developer being so interactive with their audience!
Alex Grönholm
@agronholm

quote from the docs, on adding jobs:

You can schedule jobs on the scheduler at any time. If the scheduler is not yet running when the job is added, the job will be scheduled tentatively and its first run time will only be computed when the scheduler starts.

maybe it is not directly implied but the jobs won't really be added until the scheduler is started
Tjeerd Bakker
@I_Cheered_gitlab
Yeah, I interpreted that part as "The jobs will be created (and stored), but the job won't be executed until the scheduler is started"
Alex Grönholm
@agronholm
this doesn't come up often since just about everybody does start the scheduler
Tjeerd Bakker
@I_Cheered_gitlab
Haha yeah, its the first time I'm diving into APScheduler so I'm just throwing shit at the wall until something sticks, and that comes with doing weird unexpected stuff
Alex Grönholm
@agronholm
@I_Cheered_gitlab are you the one who posted to the google group about getting next run times?
Tjeerd Bakker
@I_Cheered_gitlab
Nope
Tjeerd Bakker
@I_Cheered_gitlab
I have another question: I want to send a message to a websocket connection with some arguments at regular intervals using jobs from a persistent job store. How would I create a callable that is globally accessible that sends a message to an object instance?
# The following is heavily simplified
class WS_Handler:
    def __init__(self, websocket):
        self.websocket = websocket


    def send_message(self, message):
        self.websocket.send_text(str(message))


    def handle_event(self, device, value):
        message = {
            "device": device,
            "value": value
        }
        self.send_message(message)


def globally_accessible_target(device, value):
    # This is the target of a job
    # How to send a message to the ws_handler_instance's "handle_event" method?
    #


ws_handler_instance = WS_Handler(websocket)
Alex Grönholm
@agronholm
@I_Cheered_gitlab make the websocket connection a global variable in some module