def process_cron_triggers_v2(self, ctx): for t in triggers.get_next_cron_triggers(): LOG.debug("Processing cron trigger: %s" % t) # Setup admin context before schedule triggers. ctx = security.create_context(t.trust_id, t.project_id) auth_ctx.set_ctx(ctx) LOG.debug("Cron trigger security context: %s" % ctx) try: rpc.get_engine_client().start_workflow( t.workflow.name, t.workflow_input, description="Workflow execution created by cron trigger.", **t.workflow_params ) finally: if t.remaining_executions is not None and t.remaining_executions > 0: t.remaining_executions -= 1 if t.remaining_executions == 0: db_api_v2.delete_cron_trigger(t.name) else: # if remaining execution = None or > 0 next_time = triggers.get_next_execution_time(t.pattern, t.next_execution_time) db_api_v2.update_cron_trigger( t.name, {"next_execution_time": next_time, "remaining_executions": t.remaining_executions} ) auth_ctx.set_ctx(None)
def process_cron_triggers_v2(self, ctx): for t in triggers.get_next_cron_triggers(): LOG.debug("Processing cron trigger: %s" % t) # Setup admin context before schedule triggers. ctx = security.create_context(t.trust_id, t.project_id) auth_ctx.set_ctx(ctx) LOG.debug("Cron trigger security context: %s" % ctx) try: rpc.get_engine_client().start_workflow( t.workflow.name, t.workflow_input, description="workflow execution by cron trigger.", **t.workflow_params ) finally: if t.remaining_executions > 0: t.remaining_executions -= 1 if t.remaining_executions == 0: db_api_v2.delete_cron_trigger(t.name) else: # if remaining execution = None or > 0 next_time = triggers.get_next_execution_time( t.pattern, t.next_execution_time ) db_api_v2.update_cron_trigger( t.name, {'next_execution_time': next_time, 'remaining_executions': t.remaining_executions} ) auth_ctx.set_ctx(None)
def delete(self, name): """Delete cron trigger.""" acl.enforce('cron_triggers:delete', context.ctx()) LOG.info("Delete cron trigger [name=%s]" % name) db_api.delete_cron_trigger(name)
def advance_cron_trigger(ct): modified_count = 0 try: # If the cron trigger is defined with limited execution count. if (ct.remaining_executions is not None and ct.remaining_executions > 0): ct.remaining_executions -= 1 # If this is the last execution. if ct.remaining_executions == 0: modified_count = db_api_v2.delete_cron_trigger(ct.name) else: # if remaining execution = None or > 0. next_time = triggers.get_next_execution_time( ct.pattern, ct.next_execution_time) # Update the cron trigger with next execution details # only if it wasn't already updated by a different process. updated, modified_count = db_api_v2.update_cron_trigger( ct.name, { 'next_execution_time': next_time, 'remaining_executions': ct.remaining_executions }, query_filter={'next_execution_time': ct.next_execution_time}) except exc.NotFoundException as e: # Cron trigger was probably already deleted by a different process. LOG.debug("Cron trigger named '%s' does not exist anymore: %s", ct.name, str(e)) # Return True if this engine was able to modify the cron trigger in DB. return modified_count > 0
def delete_cron_trigger(name, trust_id=None): if not trust_id: trigger = db_api.get_cron_trigger(name) trust_id = trigger.trust_id security.delete_trust(trust_id) return db_api.delete_cron_trigger(name)
def delete_cron_trigger(name, trust_id=None): if not trust_id: trigger = db_api.get_cron_trigger(name) trust_id = trigger.trust_id modified_count = db_api.delete_cron_trigger(name) if modified_count: # Delete trust only together with deleting trigger. security.delete_trust(trust_id) return modified_count
def delete_cron_trigger(identifier, trust_id=None, delete_trust=True): if not trust_id: trigger = db_api.get_cron_trigger(identifier) trust_id = trigger.trust_id modified_count = db_api.delete_cron_trigger(identifier) if modified_count and delete_trust: # Delete trust only together with deleting trigger. security.delete_trust(trust_id) return modified_count
def advance_cron_trigger(ct): modified_count = 0 try: # If the cron trigger is defined with limited execution count. if (ct.remaining_executions is not None and ct.remaining_executions > 0): ct.remaining_executions -= 1 # If this is the last execution. if ct.remaining_executions == 0: modified_count = db_api_v2.delete_cron_trigger(ct.name) else: # if remaining execution = None or > 0. next_time = triggers.get_next_execution_time( ct.pattern, ct.next_execution_time ) # Update the cron trigger with next execution details # only if it wasn't already updated by a different process. updated, modified_count = db_api_v2.update_cron_trigger( ct.name, { 'next_execution_time': next_time, 'remaining_executions': ct.remaining_executions }, query_filter={ 'next_execution_time': ct.next_execution_time } ) except exc.NotFoundException as e: # Cron trigger was probably already deleted by a different process. LOG.debug( "Cron trigger named '%s' does not exist anymore: %s", ct.name, str(e) ) # Return True if this engine was able to modify the cron trigger in DB. return modified_count > 0
def delete(self, name): """Delete cron trigger.""" LOG.info("Delete cron trigger [name=%s]" % name) db_api.delete_cron_trigger(name)