Schedules

Schedules are regular Django models. You can manage them through the Admin pages or directly from your code with the schedule() function or the Schedule model:

from django_q import Schedule, schedule

# Use the schedule wrapper

schedule('math.copysign',
         2, -2,
         hook='hooks.print_result',
         schedule_type=Schedule.DAILY)

# Or create the object directly

Schedule.objects.create(func='math.copysign',
                        hook='hooks.print_result',
                        args='2,-2',
                        schedule_type=Schedule.DAILY
                        )

Reference

schedule(func, *args, hook=None, schedule_type='O', repeats=-1, next_run=now(), **kwargs)

Creates a schedule

Parameters:
  • func (str) – the function to schedule. Dotted strings only.
  • args – arguments for the scheduled function.
  • hook (str) – optional result hook function. Dotted strings only.
  • schedule_type (str) – (O)nce, (H)ourly, (D)aily, (W)eekly, (M)onthly, (Q)uarterly, (Y)early or Schedule.TYPE
  • repeats (int) – Number of times to repeat schedule. -1=Always, 0=Never, n =n.
  • next_run (datetime) – Next or first scheduled execution datetime.
  • kwargs – optional keyword arguments for the scheduled function.
class Schedule

A database model for task schedules.

func

The function to be scheduled

hook

Optional hook function to be called after execution.

args

Positional arguments for the function.

kwargs

Keyword arguments for the function

schedule_type

The type of schedule. Follows Schedule.TYPE

TYPE

ONCE, HOURLY, DAILY, WEEKLY, MONTHLY. QUARTERLY, YEARLY

repeats

Number of times to repeat the schedule. -1=Always, 0=Never, n =n. When set to -1, this will keep counting down.

next_run

Datetime of the next scheduled execution.

task

Name of the last task generated by this schedule.

last_run()

Admin link to the last executed task.

success()

Returns the success status of the last executed task.