Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
count = crontab.prepare_events()
print count, "events successfully prepared (stage 1)"
# Step 3 - Submit event (try until success)
print "do_events: Waiting for confirmations"
initial_bc = get_block_count()
wait_for_blocks(crontab.CONFIRMATIONS_REQUIRED,initial_bc)
count = crontab.submit_events()
while count == 0:
print "do_events: Waiting some more..."
wait_for_blocks(1)
count = crontab.submit_events()
print count, "events successfully submitted (stage 2)"
crontab.CONFIRMATIONS_REQUIRED = 1
while True:
do_test()
def create_crontab(uts):
ctab = CronTab()
if uts.cron_type == 'h':
if uts.cron_interval > 1:
interval_list = [str(x) for x in range(0, 23, uts.cron_interval)]
interval_str = ','.join(interval_list)
else:
interval_str = '*'
cronline = "%s %s * * * %s runtests %s %s >/tmp/unitTestCronjob%s.out 2>&1" % (
uts.cron_start, interval_str, os.path.join(settings.BASE_DIR, 'runmanage.sh'), uts.branch.repo.name,
uts.branch.name, uts.id)
logger.debug('Creating cron tab with line ' + cronline)
item = CronItem(line=cronline + ' #' + ('%s %d' % (CRON_COMMENT, uts.id)))
ctab.add(item)
ctab.write()
def do_events():
# Step 2 - Prepare event
count = crontab.prepare_events()
print count, "events successfully prepared (stage 1)"
# Step 3 - Submit event (try until success)
print "do_events: Waiting for confirmations"
initial_bc = get_block_count()
wait_for_blocks(crontab.CONFIRMATIONS_REQUIRED,initial_bc)
count = crontab.submit_events()
while count == 0:
print "do_events: Waiting some more..."
wait_for_blocks(1)
count = crontab.submit_events()
print count, "events successfully submitted (stage 2)"
def do_events():
# Step 2 - Prepare event
count = crontab.prepare_events()
print count, "events successfully prepared (stage 1)"
# Step 3 - Submit event (try until success)
print "do_events: Waiting for confirmations"
initial_bc = get_block_count()
wait_for_blocks(crontab.CONFIRMATIONS_REQUIRED,initial_bc)
count = crontab.submit_events()
while count == 0:
print "do_events: Waiting some more..."
wait_for_blocks(1)
count = crontab.submit_events()
print count, "events successfully submitted (stage 2)"
def do_events():
# Step 2 - Prepare event
count = crontab.prepare_events()
print count, "events successfully prepared (stage 1)"
# Step 3 - Submit event (try until success)
print "do_events: Waiting for confirmations"
initial_bc = get_block_count()
wait_for_blocks(crontab.CONFIRMATIONS_REQUIRED,initial_bc)
count = crontab.submit_events()
while count == 0:
print "do_events: Waiting some more..."
wait_for_blocks(1)
count = crontab.submit_events()
print count, "events successfully submitted (stage 2)"
def do_events():
# Step 2 - Prepare event
count = crontab.prepare_events()
print count, "events successfully prepared (stage 1)"
# Step 3 - Submit event (try until success)
print "do_events: Waiting for confirmations"
initial_bc = get_block_count()
wait_for_blocks(crontab.CONFIRMATIONS_REQUIRED,initial_bc)
count = crontab.submit_events()
while count == 0:
print "do_events: Waiting some more..."
wait_for_blocks(1)
count = crontab.submit_events()
print count, "events successfully submitted (stage 2)"
from crontab import CronTab
from bs4 import BeautifulSoup
import urllib2
from xml.dom.minidom import parse, parseString
import sys
from math import ceil
from sys import argv
import Foundation
import objc
import AppKit
import subprocess
import pickle
import time
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
tab = CronTab(user=getpass.getuser())
def notify(clear, title, subtitle, info_text, url, delay=0, sound=False, userInfo={}):
#Notification Triggering Function
notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(info_text)
notification.setHasActionButton_(True)
notification.setActionButtonTitle_("View")
notification.setUserInfo_({"action":"open_url", "value":url})
if sound:
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.setDelegate_(notification)
if clear == True:
NSUserNotificationCenter.defaultUserNotificationCenter().removeAllDeliveredNotifications()
session.get('task_query'), session.get('form_type'), session.get('task_description'),
session.get('task_frequency'), session.get('task_limit'), "Stopped",
Current_Timestamp, Current_Timestamp,))
Connection.commit()
time.sleep(1)
if session.get('task_frequency'):
Cursor.execute("SELECT * FROM tasks WHERE query = %s AND plugin = %s AND description = %s AND frequency = %s AND task_limit = %s AND status = %s AND created_at = %s AND updated_at = %s;", (
session.get('task_query'), session.get('form_type'), session.get('task_description'),
session.get('task_frequency'), str(session.get('task_limit')),
"Stopped", str(Current_Timestamp), str(Current_Timestamp),))
result = Cursor.fetchone()
current_task_id = result[0]
try:
my_cron = CronTab(user=getpass.getuser())
job = my_cron.new(command=f'/usr/bin/python3 {File_Path}/plugin_caller.py -t {str(current_task_id)}')
job.setall(session.get('task_frequency'))
my_cron.write()
Message = f"Task ID {(current_task_id)} created by {session.get('user')}."
app.logger.warning(Message)
Create_Event(Message)
except:
Frequency_Error = f"Task created but no cronjob was created due to the supplied frequency being invalid, please double check the frequency for task ID {str(session.get('task_id'))} and use the \"Edit\" button to update it in order for the cronjob to be created."
session['form_step'] = 0
Cursor.execute("SELECT * FROM tasks")
results = Cursor.fetchall()
if Frequency_Error:
return render_template('tasks.html', username=session.get('user'),
app_log.error('%s (thread): %s', name, exception)
def run_function(*args, **kwargs):
future = threadpool.submit(fn, *args, **kwargs)
future.add_done_callback(on_done)
return future
self.function = run_function
# Run on schedule if any of the schedule periods are specified
periods = 'minutes hours dates months weekdays years'.split()
if any(schedule.get(key) for key in periods):
# Convert all valid values into strings (e.g. 30 => '30'), and ignore any spaces
cron = (str(schedule.get(key, '*')).replace(' ', '') for key in periods)
self.cron_str = ' '.join(cron)
self.cron = CronTab(self.cron_str)
self.call_later()
elif not schedule.get('startup'):
app_log.warning('schedule:%s has no schedule nor startup', name)
# Run now if the task is to be run on startup. Don't re-run if the config was reloaded
startup = schedule.get('startup')
if startup == '*' or (startup is True and not ioloop_running(self.ioloop)):
self.function()
def get_schedule_interval_in_seconds(self, seconds_ago=0):
"""Return the job interval in seconds or None if there is no interval
:params seconds_ago: return an interval the job had in the past
"""
schedule = self.get_schedule()
if schedule is None:
return None
if CronSlices.is_valid(schedule):
try:
job_tz = pytz.timezone(self.get_schedule_time_zone())
except (pytz.exceptions.UnknownTimeZoneError, AttributeError):
job_tz = pytz.utc
c = croniter(schedule, datetime.datetime.now(job_tz) - datetime.timedelta(seconds=seconds_ago))
return c.get_next() - c.get_prev()
else:
try:
_, _, interval = self.get_schedule().split('/')
return int(float(isodate.parse_duration(interval).total_seconds()))
except (isodate.ISO8601Error, ValueError):
return None