django-crontask 1.2.0__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-crontask
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: Cron style scheduler for Django's task framework.
5
5
  Keywords: Django,cron,tasks,scheduler
6
6
  Author-email: Rust Saiargaliev <fly.amureki@gmail.com>, Johannes Maron <johannes@maron.family>, Mostafa Mohamed <mostafa.anm91@gmail.com>, Jacqueline Kraus <jacquelinekraus1992@gmail.com>
@@ -152,6 +152,15 @@ The monitor's slug will be the actor's name. Like `my_task` in the example above
152
152
  Certain triggers are not supported by Sentry as well as sub-minute intervals.
153
153
  In these cases, no monitor will be created and no telemetry will be sent.
154
154
 
155
+ Pass a custom config via `sentry_monitor_config` or set it to `False`
156
+ to disable Sentry monitoring for a single task:
157
+
158
+ ```python
159
+ @cron("* * * * *", sentry_monitor_config=False)
160
+ @task
161
+ def my_task_without_sentry(): ...
162
+ ```
163
+
155
164
  ### The crontask command
156
165
 
157
166
  ```ShellSession
@@ -110,6 +110,15 @@ The monitor's slug will be the actor's name. Like `my_task` in the example above
110
110
  Certain triggers are not supported by Sentry as well as sub-minute intervals.
111
111
  In these cases, no monitor will be created and no telemetry will be sent.
112
112
 
113
+ Pass a custom config via `sentry_monitor_config` or set it to `False`
114
+ to disable Sentry monitoring for a single task:
115
+
116
+ ```python
117
+ @cron("* * * * *", sentry_monitor_config=False)
118
+ @task
119
+ def my_task_without_sentry(): ...
120
+ ```
121
+
113
122
  ### The crontask command
114
123
 
115
124
  ```ShellSession
@@ -36,7 +36,11 @@ class LazyBlockingScheduler(BlockingScheduler):
36
36
  scheduler = LazyBlockingScheduler()
37
37
 
38
38
 
39
- def cron(schedule: str | BaseTrigger) -> typing.Callable[[Task], Task]:
39
+ def cron(
40
+ schedule: str | BaseTrigger,
41
+ *,
42
+ sentry_monitor_config: dict[str, typing.Any] | bool | None = None,
43
+ ) -> typing.Callable[[Task], Task]:
40
44
  """
41
45
  Run task on a scheduler with a cron schedule.
42
46
 
@@ -46,8 +50,10 @@ def cron(schedule: str | BaseTrigger) -> typing.Callable[[Task], Task]:
46
50
  def cron_test():
47
51
  print("Cron test")
48
52
 
49
- Sentry cron monitors are automatically upserted on every check-in
50
- using the task name as the monitor slug.
53
+ Args:
54
+ schedule: A cron schedule string or an APScheduler trigger.
55
+ sentry_monitor_config: A Sentry monitor configuration dict or False to disable monitoring.
56
+
51
57
  """
52
58
 
53
59
  def decorator(task: Task) -> Task:
@@ -67,7 +73,12 @@ def cron(schedule: str | BaseTrigger) -> typing.Callable[[Task], Task]:
67
73
  else:
68
74
  trigger = schedule
69
75
 
70
- task = sentry.monitor_cron_task(task, trigger)
76
+ if sentry_monitor_config is not False:
77
+ task = sentry.monitor_cron_task(
78
+ task,
79
+ trigger,
80
+ sentry_monitor_config=sentry_monitor_config,
81
+ )
71
82
 
72
83
  scheduler.add_job(
73
84
  func=task.enqueue,
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '1.2.0'
22
- __version_tuple__ = version_tuple = (1, 2, 0)
21
+ __version__ = version = '1.3.0'
22
+ __version_tuple__ = version_tuple = (1, 3, 0)
23
23
 
24
- __commit_id__ = commit_id = 'gae12a07e2'
24
+ __commit_id__ = commit_id = 'g64b289130'
@@ -1,5 +1,3 @@
1
- import typing
2
-
3
1
  from apscheduler.triggers.base import BaseTrigger
4
2
  from apscheduler.triggers.calendarinterval import CalendarIntervalTrigger
5
3
  from apscheduler.triggers.cron import CronTrigger
@@ -8,7 +6,9 @@ from django.tasks import Task
8
6
  from django.utils import timezone
9
7
 
10
8
 
11
- def trigger_to_monitor_config(trigger: BaseTrigger) -> dict[str, typing.Any] | None:
9
+ def trigger_to_monitor_config(
10
+ trigger: BaseTrigger,
11
+ ) -> dict[str, dict[str, str | int] | str] | None:
12
12
  """Convert an APScheduler trigger to a Sentry monitor configuration if possible."""
13
13
  tz = str(timezone.get_default_timezone())
14
14
  match trigger:
@@ -62,7 +62,11 @@ def trigger_to_monitor_config(trigger: BaseTrigger) -> dict[str, typing.Any] | N
62
62
  return None
63
63
 
64
64
 
65
- def monitor_cron_task(task: Task, trigger: BaseTrigger) -> Task:
65
+ def monitor_cron_task(
66
+ task: Task,
67
+ trigger: BaseTrigger,
68
+ sentry_monitor_config: dict[str, dict[str, str | int] | str] | None = None,
69
+ ) -> Task:
66
70
  """
67
71
  Wrap the task function in a Sentry monitor for a suitable trigger.
68
72
 
@@ -75,7 +79,9 @@ def monitor_cron_task(task: Task, trigger: BaseTrigger) -> Task:
75
79
  except ImportError:
76
80
  return task
77
81
  else:
78
- if monitor_config := trigger_to_monitor_config(trigger):
82
+ if monitor_config := sentry_monitor_config or trigger_to_monitor_config(
83
+ trigger
84
+ ):
79
85
  return type(task)(
80
86
  priority=task.priority,
81
87
  func=monitor(task.name, monitor_config=monitor_config)(task.func),
@@ -41,5 +41,7 @@ def extend_lock(lock, scheduler):
41
41
  try:
42
42
  lock.extend(get_settings().LOCK_TIMEOUT, True)
43
43
  except LockError:
44
- scheduler.shutdown()
44
+ # `extend_lock` runs inside a scheduler worker thread;
45
+ # shutdown must be done from there to avoid a deadlock on the lock.
46
+ scheduler.shutdown(wait=False)
45
47
  raise
File without changes