Example #1
0
def process_task(user):
    """
    This worker is responsible for creating entries on the platform
    :param user: a user object
    :param entry: contains the information about the entry which should be created on the platform
    :param status: contains for which task is the entry
    """
    task = Task(user)
    task.create()

    report = Report(user, COSMOS_TRACKER)
    report.send()
Example #2
0
def test_tasks():
    task = Task()
    assert task.count == 1
    assert len(task.get_tasks()) == 0
    new_process_function(to_test_th)
    assert task.count == 2
    assert len(task.get_tasks()) == 1
    task.kill_task(1)
    assert task.count == 2
    assert len(task.get_tasks()) == 0
    new_process_function(to_test_th)
    task.kill_task(1)
    assert task.count == 3
    assert len(task.get_tasks()) == 1
    task.kill_task(2)
    assert len(task.get_tasks()) == 0
Example #3
0
def new_process_command(command, name="Unknown"):
    """Runs a system command and saves it in Tasks
    
    Args:
        command (list/str): command to run
        name (str, optional): Name of the process. Defaults to "Unknown".
    """
    if not (type(command) == type([])):
        command = command.split(" ")
    q = multiprocessing.Queue()
    th = CustomProcess(name=name, target=_popen_run, args=(q, command))
    th.start()
    #th.join()
    pid = q.get()
    Task().get_instance().add_task(th, pid)
    print_info("Task running in background... use 'tasks list' to check")
Example #4
0
def new_process_function(func, args=None, name="Unknown", seconds_to_wait=0):
    """Runs a python function and saves it in Task
    
    Args:
        func (func): Function type
        args (list, optional): List of args of the funcion. Defaults to None.
        name (str, optional): Name of the process. Defaults to "Unknown".
        seconds_to_wait (int, optional): Seconds to wait to execute the function. Defaults to 0.
    """
    try:
        if args:
            th = CustomProcess(name=name, target=func, args=(args, ))
        else:
            th = CustomProcess(name=name, target=func)
        th.start()
        Task().get_instance().add_task(th, th.pid, seconds_to_wait)
        print_info("Task running in background... use 'tasks list' to check")
    except:
        pass
Example #5
0
 def _exit(self, param=None):
     print_info("Killing tasks... ")
     Task().get_instance().kill_all_tasks()
     print_info("Bye...")
     _exit(0)
Example #6
0
 def _task(self, params):
     if "list" in params:
         Task().get_instance().show_tasks()
     elif "kill" in params and len(params) >= 2:
         Task().get_instance().kill_task(params[1])