Home > Software engineering >  APS Scheduler raising exception for no reason django
APS Scheduler raising exception for no reason django

Time:11-06

Even though the target function is receiving both the arguments it's still throwing an error for missing parameters ? wonder why

check_device() missing 1 required positional argument: 'device_id'
    Job "check_device (trigger: interval[0:00:30], next run at: 2021-11-05 19:35:24 IST)" raised an exception

Scheduler snip

def job_add(application_id,device_id,count):
    scheduler.add_job(
        check_device,
        'interval',
        args = (application_id,device_id,),
        seconds=7,
        jobstore = 'default',
        id=f'my_job_{count}',
        replace_existing=True,
        max_instances = 7,
        misfire_grace_time=None
    )

function i am calling

def check_device(application_id,device_id):
    print('Mqtt connected ... calling on ',application_id,device_id)
    mqttc = mqtt.Client(clientId)

CodePudding user response:

Here is a dummy version of your code which works. Make sure you pass the arguments and call the functions correctly :

from apscheduler.schedulers.blocking import BlockingScheduler


def check_device(application_id, device_id):
    print(f"Application id: {application_id}, Device id: {device_id}")


scheduler = BlockingScheduler()


def job_add(application_id, device_id, count):
    scheduler.add_job(
        check_device,
        "interval",
        args=(
            application_id,
            device_id,
        ),
        seconds=2,
        jobstore="default",
        id=f"my_job_{count}",
        replace_existing=True,
        max_instances=7,
        misfire_grace_time=None,
    )


job_add(application_id=5, device_id=2, count=1)
scheduler.start()

CodePudding user response:

Okay so posting this answer for future reference , I believe APS stores every job (function) signature in someway in the database I previously added a job with one parameter, after making changes it was searching for the previously defined function as well, but it had no positional parameter for device_id , Solution , just delete previous job history from DB ( this answer may not be precise but if it seems to be giving the above mention error for no reason, deleting related job history should do the job)

  • Related