我正在使用celery任务来实现一个执行git代码的代码。该任务从git repo(主分支)获取代码,将其克隆到运行celery的计算机中并执行代码。如果计算机上存在该代码的本地副本,则该任务将执行该本地副本,或者如果master分支中有任何更改,则该任务将提取更改并执行。
我当前面临的问题是,如果我在本地对存储库进行更改并执行任务,那么它就不会在本地进行更改。如果仅重新启动celery,则可以执行本地修改的代码。
我的芹菜设置。
celery.py
"""Celery entrypoint"""
from celery import Celery
from waves.wavequeue import celery_config
app = Celery()
app.config_from_object(celery_config)
celery_config.py
"""Celery configuration"""
broker_url = 'redis://localhost'
result_backend = 'redis://localhost'
include = ['waves.core.execute', 'waves.waveengine.tasks']
worker_redirect_stdouts = False
result_expires = 3600
worker_hijack_root_logger = True
# Fix Hard time limit (300.0s) exceeded for task
task_time_limit = 86400 # 1 day
task_soft_time_limit = 86400 # 1 day
task_serializer = 'json'
我已经定义了一个自定义任务,如下所示:
class WaveTask(celery.Task):
@abstractmethod
def run(self, *args, **kwargs):
pass
def on_success(self, retval, task_id, args, kwargs):
logger.info('on_success task_id=%s retval=%s args=%s kwargs=%s', task_id, retval, args, kwargs)
def on_retry(self, exc, task_id, args, kwargs, einfo):
logger.error('on_retry task_id=%s exc=%s args=%s kwargs=%s einfo=%s', task_id, exc, args, kwargs, einfo)
def on_failure(self, exc, task_id, args, kwargs, einfo):
logger.error('on_failure task_id=%s exc=%s args=%s kwargs=%s einfo=%s', task_id, exc, args, kwargs, einfo)
waveengine / tasks.py
from waves.waveengine.wave_engine import run_wavelet
from waves.wavequeue.celery import app
from waves.wavequeue.wave_task import WaveTask
@app.task(base=WaveTask)
def run_wavelet_async(instance_id, wavelet_id, last_wavelet_id, wavelet: dict) -> bool:
return run_wavelet(instance_id, wavelet_id, last_wavelet_id, wavelet)
@app.task(base=WaveTask)
def run_wavelet_sync(instance_id, wavelet_id, last_wavelet_id, wavelet: dict) -> bool:
return run_wavelet(instance_id, wavelet_id, last_wavelet_id, wavelet)
上述任务在内部运行一个函数run_wavelet()函数,该函数执行所拾取的代码。
在解决上述问题方面的任何帮助将不胜感激。