Celery仅在接下来的5天内定期运行任务

时间:2016-05-04 10:04:59

标签: rabbitmq celery celery-task celerybeat

我有一个芹菜任务,我需要它在下午12点30分才开始运行。我怎么用celery-beat做这件事。我知道如何定期运行它,但不知道接下来的五天任何想法?

1 个答案:

答案 0 :(得分:0)

查看crontab的celery-beat docs。虽然这实际上是一次性的事情,但根据定义,它并不是完全周期性的。您可以设置一个crontab定期任务,在接下来的5天内在上午12:30运行,但您还必须记得手动将其关闭。

如果你走这条路

from celery.schedules import crontab

CELERYBEAT_SCHEDULE = {
    'add-at-midnightish': {
        'task': 'tasks.add',
        'schedule': crontab(hour=0, minute=30,),
        'args': (16, 16),
    },
}

或者,您可以使用eta

中提到的apply_async上的package test; import java.io.*; import java.util.Scanner; public class test { //Main Method public static void main (String args[]) { String origFileName = "zuess.txt"; String newFileName = "NewFile.txt"; PrintWriter outputStream = null; try { outputStream = new PrintWriter (new File(newFileName)); } catch (FileNotFoundException e1) { System.out.println("Error opening the file " + origFileName); System.exit(0); } Scanner inputStream = null; try { inputStream = new Scanner (new File(origFileName)); } catch (FileNotFoundException e1) { System.out.println("Error opening the file " + origFileName); System.exit(0); } while(inputStream.hasNextLine()) { String line = inputStream.nextLine(); String[] arr = line.split(" "); for(int i = 1; i < arr.length; i++) outputStream.write(arr[i]+" "); outputStream.println(); } outputStream.close(); inputStream.close(); try { inputStream = new Scanner( new File (newFileName)); } catch(FileNotFoundException e) { System.out.println("Error opening the file " + newFileName); System.exit(0); } System.out.println("The file " + newFileName + " Contains the following lines: "); while (inputStream.hasNextLine()) { String text = inputStream.nextLine(); System.out.println(text); } inputStream.close(); }//End main }//end class 关键字