Exemplo n.º 1
0
def add_cron_script(plan_name, script, interval):
    cron = Plan(plan_name,
                path=os.path.dirname(os.path.realpath(script)),
                environment=_environment)

    output = {
        'stdout': '/tmp/%s.stdout.log' % (os.path.basename(script)),
        'stderr': '/tmp/%s.stderr.log' % (os.path.basename(script))
    }

    if interval == 'hourly':
        cron.script(os.path.abspath(script),
                    every='1.hour',
                    at='minute.5 minute.15 minute.30 minute.45',
                    output=output)

    elif interval == 'daily':
        cron.script(os.path.abspath(script),
                    every='1.day',
                    at='0:05 4:00 8:00 12:00 16:00 20:00',
                    output=output)

    elif interval == 'weekly':
        cron.script(os.path.abspath(script),
                    every='monday',
                    at='0:05 4:00 8:00 12:00 16:00 20:00',
                    output=output)

    elif isinstance(interval, int):
        cron.script(os.path.abspath(script),
                    every='%d.minute' % (interval / 60),
                    output=output)

    cron.run('update')
Exemplo n.º 2
0
def DestroyPlan(command):
    """
    取消指定任务
    :param command:
    :return:
    """
    cron = Plan(command)
    # cron.command('node index.js', every='1.day', at='16:19')
    cron.run('clear')
Exemplo n.º 3
0
def CreatePlan(command):
    """
    创建指定命令任务
    :param command:
    :return:
    """
    cron = Plan(command)
    cron.command('node ' + path + '/index.js ' + command, every='1.day', at='16:51')
    cron.run('write')
Exemplo n.º 4
0
# Copyright 2014 CourseApp.me All rights reserved
#
# Authors: Paul D'Amora
# run.py runs entirely independent of flask and courseapp as a whole
# it simply write schedule.py to crontab which will contain all periodic tasks

from plan import Plan

cron = Plan()

# Add this script to the cron object and run it every 10 minutes
#cron.script('schedule.py', every='10.minute')

# This file needs to be ran from the terminal
# cron.run takes a bunch of different options
if __name__ == '__main__':
    cron.run('write') # could be 'check', 'write', 'update', 'clear'
Exemplo n.º 5
0
from plan import Plan


cron = Plan(__name__)

cron.script('test', every='5.minute')

cron.run('update')
Exemplo n.º 6
0
import argparse
import os

from plan import Plan

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SCRIPT_NAME = "ping-app/cron.py"
SCRIPT_NAME_PATH = os.path.join(BASE_DIR, SCRIPT_NAME)

cron = Plan()

cron.command(f"python3 {SCRIPT_NAME_PATH}", every="1.minute")

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-s", "--start", action="store_true")
    parser.add_argument("-e", "--end", action="store_true")
    args = parser.parse_args()

    if args.start:
        os.system(f"python3 {SCRIPT_NAME_PATH}  --init"
                  )  # call the command first and then call every 1.minutes
        cron.run("write")
    elif args.end:
        cron.run("clear")
    else:
        cron.run("clear")
from plan import Plan

cron = Plan()

cron.command('python /vagrant/stackoverflow.py', every='1.day', at='12:05')
cron.command('python /vagrant/questions_monthly.py', every='1.month')
cron.command('python /vagrant/sendEmail.py', every='1.month')



if __name__ == '__main__':
    cron.run('write')
# Package Details:
# http://plan.readthedocs.org/index.html

import os
from plan import Plan

cron = Plan()

path = os.getcwd()
cmd = "python " + path

cron.script("hello_job.py", path=path, every="1.minute")


if __name__ == "__main__":
    cron.run("write")
Exemplo n.º 9
0
# -*- coding: utf-8 -*-

# Use this file to easily define all of your cron jobs.
#
# It's helpful to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
#
# Learn more: http://github.com/fengsp/plan

from plan import Plan

cron = Plan("scripts",
            path='/web/yourproject/scripts',
            environment={'YOURAPP_ENV': 'production'})

cron.script('script.py', every='1.day')
cron.script('script_2.py', every='1.month', at='hour.12 minute.0')
# more scripts here

if __name__ == "__main__":
    cron.run('update')
Exemplo n.º 10
0
# -*- coding: utf-8 -*-
"""
    demo
    ~~~~

    :copyright: (c) 2014 by Shipeng Feng.
    :license: BSD, see LICENSE for more details.
"""

from plan import Plan

cron = Plan()

cron.command('ls /tmp', every='1.day', at='12:00')
cron.command('pwd', every='2.month')
cron.command('date', every='weekend')

if __name__ == "__main__":
    cron.run()
Exemplo n.º 11
0
from plan import Plan
import os

if __name__ == "__main__":
    ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    cron = Plan("commands")
    # online
    cron.command('/usr/local/bin/node %s/ghost/online.js' % ROOT_PATH,
                 every='1.day',
                 at="hour.21 minute.30",
                 output=dict(stdout='%s/log/online_stdout.log' % ROOT_PATH,
                             stderr='%s/log/online_stderr.log' % ROOT_PATH))
    # offline
    cron.command('/usr/local/bin/node %s/ghost/offline.js' % ROOT_PATH,
                 every='1.day',
                 at="hour.7",
                 output=dict(stdout='%s/log/offline_stdout.log' % ROOT_PATH,
                             stderr='%s/log/offline_stderr.log' % ROOT_PATH))

    cron.run("check")
    cron.run("write")
Exemplo n.º 12
0
import os

from plan import Plan

pjoin = os.path.join
dir_path = os.path.dirname(os.path.realpath(__file__))

# Django command
#
exchanger = Plan(
    'lifecycle',
    path=pjoin(dir_path, '../scraper'),
    environment={'DJANGO_SETTINGS_MODULE': 'scraper.settings_production'}
)

cmd = 'manage.py lifecycle >> /tmp/django_lifecycle.log 2>&1'
exchanger.script(cmd, every='1.days', at='minute.20')

if __name__ == "__main__":
    exchanger.run('update')
Exemplo n.º 13
0
Arquivo: run.py Projeto: scalaview/leo
from plan import Plan
import os

if __name__ == "__main__":
    ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    cron = Plan("commands")
    cron.command(
        '%s/sync_order_state_script.sh %s/..' % (ROOT_PATH, ROOT_PATH),
        every='1.minute',
        output=dict(stdout='%s/../log/sync_order_state_stdout.log' % ROOT_PATH,
                    stderr='%s/../log/sync_order_state_stderr.log' %
                    ROOT_PATH))

    cron.run("check")
    cron.run("update")
Exemplo n.º 14
0
    today = games[games.date_utc.dt.date == mydate]

    curr_date = datetime.datetime.today()
    run_date = curr_date + datetime.timedelta(minutes=1)

    print(datetime.datetime.today())
    print(run_date)
    print(run_date.strftime('%H:%M'))

    min = run_date.minute
    hour = run_date.hour
    month = run_date.month
    dom = run_date.day
    dow = run_date.weekday() + 1
    year = run_date.year

    print(min, hour, month, dom, dow)

    cron = Plan()
    command3 = '/usr/local/bin/python3 /Users/mc/Desktop/rugby-pass-scraper/scrape_match.py'
    every = '%s %s %s %s %s' % (
        min,
        hour,
        dom,
        month,
        dow,
    )
    cron.command(command3, every=every, at=str(hour) + ':' + str(min))
    cron.command(command3, every=every, at=str(hour) + ':' + str(min + 1))
    cron.run('write')
Exemplo n.º 15
0
import subprocess

from plan import Plan

from utils.config import get_environment, get_task_specs


config = get_environment('plan')
config['environment'] = dict(config['environment'])
cron = Plan(**config)
log_path = os.path.abspath(os.path.join(config.path,'logs'))
modules_path = os.path.abspath(os.path.join(config.path,'modules'))

for task in get_environment('tasks'):
    task_specs = get_task_specs(task['name'])
    cron.script(**task_specs)

if __name__ == "__main__":
    command = sys.argv[1]
    if command == 'write':
        if not os.path.exists('logs'):
            os.makedirs('logs')
        c = subprocess.Popen("crabd-check", stdout=subprocess.PIPE, shell=True)
        print(c)
    elif command == 'clear':
        if os.path.exists('logs'):
            shutil.rmtree('logs', ignore_errors=True)
        c = subprocess.Popen("killall crabd", stdout=subprocess.PIPE, shell=True)
        print(c)
    cron.run(command) #write, check, update or clear the crontab
Exemplo n.º 16
0
Arquivo: cron.py Projeto: ouchao/cron
	jobname	='job%s-%s'%(str(j['id']),j['every'])
	logsdir	='%s/Logs/cronlogs/%s'%(os.getcwd(),jobname)

	try:
		os.makedirs(logsdir)
	except Exception,e:
		pass


	exec_command='PATH=$PATH && %s'%j['cmd']
	output      = dict(stdout='%s/%s.stdout.log'%(logsdir,jobname), stderr='%s/%s.stderr.log'%(logsdir,jobname) )

	cron = Plan(name='job'+str(j['id']))
	if j.has_key('at') :
		r=cron.command(exec_command,every=j['every'],at=j['at'],output=output,)
	else:
		r=cron.command(exec_command,every=j['every'],output=output,)

	cron.run(j['action'])
	return True

if __name__ == '__main__':
	#job1={'id':1,'cmd':'date','every':'2.day','action':'update','at':'hour.12 minute.15 minute.45'}
	job2={'id':2,'cmd':'/home/qilong/python/cron/1.sh','every':'1.hour','action':'update','at':'minute.10'}
	crontab(job2)

	#print job2
	#job2=sys.argv[1]
	#crontab(eval(job2))
Exemplo n.º 17
0
from plan import Plan

cron = Plan()

cron.command('python script.py', every='1.minute')
# cron.script('script.py', every='1.day', path='/web/yourproject/scripts',
                         # environment={'YOURAPP_ENV': 'production'})

# if __name__ == "__main__":
cron.run(run_type='write')
Exemplo n.º 18
0
# -*- coding: utf-8 -*-

# Use this file to easily define all of your cron jobs.
#
# It's helpful to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
#
# Learn more: http://github.com/fengsp/plan

from plan import Plan

cron = Plan()

# register one command, script or module
# cron.command('command', every='1.day')
# cron.script('script.py', path='/web/yourproject/scripts', every='1.month')
# cron.module('calendar', every='feburary', at='day.3')

if __name__ == "__main__":
    cron.run()
Exemplo n.º 19
0
# -*- coding: utf-8 -*-
from plan import Plan

cron = Plan()

output = dict(stdout='/var/log/stdout.log', stderr='/var/log/stderr.log')

cron.command('top', every='1.hour', output=output)
cron.command('echo ok', path='/home', every='1.minute', output=output)

if __name__ == '__main__':
    cron.run("write")
Exemplo n.º 20
0
from plan import Plan
from os import getcwd

WORKING_DIR = getcwd() + '/../'
cron = Plan("lyket_ingestion_cron")

cron.script('LyketJob.py', every='5.minutes', path=WORKING_DIR)

if __name__ == '__main__':
    try:
        cron.run('update')
    except:
        cron.run('write')
Exemplo n.º 21
0
# -*- coding: utf-8 -*-

from plan import Plan

cron = Plan()

# cron.script('script.py', path='/web/yourproject/scripts', every='1.month')

if __name__ == "__main__":
    cron.run('check')
    # cron.run('clear')
    # cron.run('update')
    # cron.run('write')