climate-ref-celery 0.5.0__py3-none-any.whl → 0.5.2__py3-none-any.whl

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.
climate_ref_celery/cli.py CHANGED
@@ -54,6 +54,7 @@ def import_provider(provider_package: str) -> DiagnosticProvider:
54
54
 
55
55
  @app.command()
56
56
  def start_worker(
57
+ ctx: typer.Context,
57
58
  loglevel: str = typer.Option("info", help="Log level for the worker"),
58
59
  package: str | None = typer.Option(help="Package to import tasks from", default=None),
59
60
  extra_args: list[str] = typer.Argument(None, help="Additional arguments for the worker"),
@@ -75,6 +76,10 @@ def start_worker(
75
76
  # Attempt to import the provider
76
77
  provider = import_provider(package)
77
78
 
79
+ if hasattr(ctx.obj, "config"):
80
+ # Configure the provider so that it knows where the conda environments are
81
+ provider.configure(ctx.obj.config)
82
+
78
83
  # Wrap each diagnostics in the provider with a celery tasks
79
84
  register_celery_tasks(celery_app, provider)
80
85
  queue = provider.slug
@@ -84,7 +89,7 @@ def start_worker(
84
89
 
85
90
  queue = "celery"
86
91
 
87
- argv = ["worker", f"--loglevel={loglevel}", f"--queues={queue}", *(extra_args or [])]
92
+ argv = ["worker", "-E", f"--loglevel={loglevel}", f"--queues={queue}", *(extra_args or [])]
88
93
  celery_app.worker_main(argv=argv)
89
94
 
90
95
 
@@ -14,9 +14,8 @@ from climate_ref.config import Config
14
14
  from climate_ref.models import Execution
15
15
  from climate_ref_celery.app import app
16
16
  from climate_ref_celery.tasks import generate_task_name
17
- from climate_ref_core.diagnostics import Diagnostic, ExecutionDefinition, ExecutionResult
17
+ from climate_ref_core.diagnostics import ExecutionDefinition, ExecutionResult
18
18
  from climate_ref_core.executor import Executor
19
- from climate_ref_core.providers import DiagnosticProvider
20
19
 
21
20
 
22
21
  class CeleryExecutor(Executor):
@@ -43,8 +42,6 @@ class CeleryExecutor(Executor):
43
42
 
44
43
  def run(
45
44
  self,
46
- provider: DiagnosticProvider,
47
- diagnostic: Diagnostic,
48
45
  definition: ExecutionDefinition,
49
46
  execution: Execution | None = None,
50
47
  ) -> None:
@@ -62,10 +59,6 @@ class CeleryExecutor(Executor):
62
59
 
63
60
  Parameters
64
61
  ----------
65
- provider
66
- Provider for the diagnostic
67
- diagnostic
68
- Diagnostic to run
69
62
  definition
70
63
  A description of the information needed for this execution of the diagnostic
71
64
  This includes relative paths to the data files,
@@ -78,12 +71,14 @@ class CeleryExecutor(Executor):
78
71
  """
79
72
  from climate_ref_celery.worker_tasks import handle_result
80
73
 
81
- name = generate_task_name(provider, diagnostic)
74
+ diagnostic = definition.diagnostic
75
+
76
+ name = generate_task_name(diagnostic.provider, diagnostic)
82
77
 
83
78
  async_result = app.send_task(
84
79
  name,
85
80
  args=[definition, self.config.log_level],
86
- queue=provider.slug,
81
+ queue=diagnostic.provider.slug,
87
82
  link=handle_result.s(execution_id=execution.id).set(queue="celery") if execution else None,
88
83
  )
89
84
  logger.debug(f"Celery task {async_result.id} submitted")
@@ -13,13 +13,10 @@ The main process is responsible for tracking what diagnostics have been register
13
13
  and to respond to new workers coming online.
14
14
  """
15
15
 
16
- from collections.abc import Callable
17
-
18
16
  from celery import Celery
19
- from loguru import logger
20
17
 
21
- from climate_ref_core.diagnostics import Diagnostic, ExecutionDefinition, ExecutionResult
22
- from climate_ref_core.logging import redirect_logs
18
+ from climate_ref_core.diagnostics import Diagnostic
19
+ from climate_ref_core.executor import execute_locally
23
20
  from climate_ref_core.providers import DiagnosticProvider
24
21
 
25
22
 
@@ -30,32 +27,6 @@ def generate_task_name(provider: DiagnosticProvider, diagnostic: Diagnostic) ->
30
27
  return f"{provider.slug}.{diagnostic.slug}"
31
28
 
32
29
 
33
- def _diagnostic_task_factory(
34
- diagnostic: Diagnostic,
35
- ) -> Callable[
36
- [ExecutionDefinition, str],
37
- ExecutionResult,
38
- ]:
39
- """
40
- Create a new task for the given diagnostic
41
- """
42
-
43
- def task(definition: ExecutionDefinition, log_level: str) -> ExecutionResult:
44
- """
45
- Task to run the diagnostic
46
- """
47
- logger.info(f"Running diagnostic {diagnostic.name} with definition {definition}")
48
- try:
49
- with redirect_logs(definition, log_level):
50
- return diagnostic.run(definition)
51
- except Exception:
52
- logger.exception(f"Error running diagnostic {diagnostic.slug}:{definition.key}")
53
- # TODO: This exception should be caught and a unsuccessful result returned.
54
- raise
55
-
56
- return task
57
-
58
-
59
30
  def register_celery_tasks(app: Celery, provider: DiagnosticProvider) -> None:
60
31
  """
61
32
  Register all tasks for the given provider
@@ -69,10 +40,14 @@ def register_celery_tasks(app: Celery, provider: DiagnosticProvider) -> None:
69
40
  provider
70
41
  The provider to register tasks for
71
42
  """
72
- for metric in provider.diagnostics():
73
- print(f"Registering task for diagnostic {metric.name}")
43
+ for diagnostic in provider.diagnostics():
44
+ print(f"Registering task for diagnostic {diagnostic.name}")
45
+
46
+ # The task function is the same for all diagnostics
47
+ # The diagnostic is included in the definition
48
+ # The queue is important to ensure that the task is run in the correct worker
74
49
  app.task( # type: ignore
75
- _diagnostic_task_factory(metric),
76
- name=generate_task_name(provider, metric),
50
+ execute_locally,
51
+ name=generate_task_name(provider, diagnostic),
77
52
  queue=provider.slug,
78
53
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: climate-ref-celery
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Celery app for mananging tasks and workers
5
5
  Author-email: Jared Lewis <jared.lewis@climate-resource.com>
6
6
  License-File: LICENCE
@@ -1,17 +1,17 @@
1
1
  climate_ref_celery/__init__.py,sha256=f-dS4JxMLmTCobZtftGDi6bUbtYCv_9iWqxSpC74tWw,129
2
2
  climate_ref_celery/app.py,sha256=wLzAnrpzkwZLYY6HY_riHUEtjiRQpkKDSeKZpyMTxAQ,1694
3
- climate_ref_celery/cli.py,sha256=-bkyEc8pJ5hV2tat7gRzGHoCGWP9qQrJIJ1KvZ3941k,2992
4
- climate_ref_celery/executor.py,sha256=RtpbelMoxI2i-Wu7NYrBzQIp07gJce2yPLUsM16w7kc,4944
3
+ climate_ref_celery/cli.py,sha256=ZQ86XdrBZoBVmgV7WCFp_P6LNCT1hFfM0zXahkK0p-E,3196
4
+ climate_ref_celery/executor.py,sha256=Qsx1bvM_-H3eMeg5VsJAV6ghHuGK3WnYyIRAd0-1DG4,4764
5
5
  climate_ref_celery/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- climate_ref_celery/tasks.py,sha256=vA7gvESuXMp3BT9Bz6ULNypDSRUUkvAHHRjumf3I3sU,2629
6
+ climate_ref_celery/tasks.py,sha256=6Ra2H48edbcklsf6pAj1JNfzi67n6WQCUXJs-tloE80,1941
7
7
  climate_ref_celery/worker_tasks.py,sha256=slUprhM8G14D3r6RACSh2alzj-_JWXU4JKG5GR0GLpA,1194
8
8
  climate_ref_celery/celeryconf/__init__.py,sha256=xKcHhnECGZAxrjnMtfaPBU_vgqwRbRLXFw8WVQ7WxaE,314
9
9
  climate_ref_celery/celeryconf/base.py,sha256=uXaz9S_1hCdwKpvyWBDWE69YVIXHD3Ar7egNKLk9Gx8,484
10
10
  climate_ref_celery/celeryconf/dev.py,sha256=um7hvEhlTBfwey9ler_vAHAln_DrpqAP3fbbO2wdmUQ,217
11
11
  climate_ref_celery/celeryconf/prod.py,sha256=HyGTfwTZD8MjIkfkb3qyfzjjTPE9sKAoXNq3fJDFO9Q,231
12
- climate_ref_celery-0.5.0.dist-info/METADATA,sha256=zkB5LN8wUrSswFvN7knOH4mcUJ50bpHouaETWUshoi0,3567
13
- climate_ref_celery-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- climate_ref_celery-0.5.0.dist-info/entry_points.txt,sha256=U9b-T6EpLV3ZXmHUpEzp8x5TZnCjQ1ynncIkFMwDuPE,58
15
- climate_ref_celery-0.5.0.dist-info/licenses/LICENCE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
16
- climate_ref_celery-0.5.0.dist-info/licenses/NOTICE,sha256=4qTlax9aX2-mswYJuVrLqJ9jK1IkN5kSBqfVvYLF3Ws,128
17
- climate_ref_celery-0.5.0.dist-info/RECORD,,
12
+ climate_ref_celery-0.5.2.dist-info/METADATA,sha256=QhFLy2WjUW2PCQlBwMUoJVzXeWcn93TAr9S9Z4GQ5ps,3567
13
+ climate_ref_celery-0.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ climate_ref_celery-0.5.2.dist-info/entry_points.txt,sha256=U9b-T6EpLV3ZXmHUpEzp8x5TZnCjQ1ynncIkFMwDuPE,58
15
+ climate_ref_celery-0.5.2.dist-info/licenses/LICENCE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
16
+ climate_ref_celery-0.5.2.dist-info/licenses/NOTICE,sha256=4qTlax9aX2-mswYJuVrLqJ9jK1IkN5kSBqfVvYLF3Ws,128
17
+ climate_ref_celery-0.5.2.dist-info/RECORD,,