Esempio n. 1
0
def scheduler_task(site, event, handler, now=False):
	from frappe.utils.scheduler import log
	traceback = ""
	task_logger.info('running {handler} for {site} for event: {event}'.format(handler=handler, site=site, event=event))
	try:
		frappe.init(site=site)
		if not create_lock(handler):
			return
		if not now:
			frappe.connect(site=site)
		frappe.get_attr(handler)()

	except Exception:
		frappe.db.rollback()
		traceback = log(handler, "Method: {event}, Handler: {handler}".format(event=event, handler=handler))
		task_logger.warn(traceback)
		raise

	else:
		frappe.db.commit()

	finally:
		delete_lock(handler)

		if not now:
			frappe.destroy()

	task_logger.info('ran {handler} for {site} for event: {event}'.format(handler=handler, site=site, event=event))
Esempio n. 2
0
def enqueue_events(site):
	if is_scheduler_disabled():
		return

	# lock before queuing begins
	lock = create_lock('scheduler')
	if not lock:
		return

	nowtime = frappe.utils.now_datetime()
	last = frappe.db.get_value('System Settings', 'System Settings', 'scheduler_last_event')

	# set scheduler last event
	frappe.db.begin()
	frappe.db.set_value('System Settings', 'System Settings', 'scheduler_last_event', nowtime.strftime(DATETIME_FORMAT), update_modified=False)
	frappe.db.commit()

	out = []
	if last:
		last = datetime.strptime(last, DATETIME_FORMAT)
		out = enqueue_applicable_events(site, nowtime, last)

	delete_lock('scheduler')

	return '\n'.join(out)
Esempio n. 3
0
def enqueue_events(site):
	if is_scheduler_disabled():
		return

	# lock before queuing begins
	try:
		lock = create_lock('scheduler')
		if not lock:
			return
	except LockTimeoutError:
		return

	nowtime = frappe.utils.now_datetime()
	last = frappe.db.get_global('scheduler_last_event')

	# set scheduler last event
	frappe.db.begin()
	frappe.db.set_global('scheduler_last_event', nowtime.strftime(DATETIME_FORMAT))
	frappe.db.commit()

	out = []
	if last:
		last = datetime.strptime(last, DATETIME_FORMAT)
		out = enqueue_applicable_events(site, nowtime, last)

	delete_lock('scheduler')

	return '\n'.join(out)
Esempio n. 4
0
def enqueue_events_for_site(site):
	try:
		frappe.init(site=site)
		if frappe.local.conf.maintenance_mode or frappe.conf.disable_scheduler:
			return
		frappe.connect(site=site)
		enqueue_events(site)
	except:
		task_logger.error('Exception in Enqueue Events for Site {0}'.format(site))
		raise
	finally:
		delete_lock('enqueue')
		frappe.destroy()
Esempio n. 5
0
	def unlock(self):
		'''Delete the lock file for this document'''
		file_lock.delete_lock(self.get_signature())