<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def factory(start_immediately=True):
 """ This is a decorator function that creates new `Job`s with the wrapped function as the target. # Example ```python @Job.factory() def some_longish_function(job, seconds):
 time.sleep(seconds) return 42 job = some_longish_function(2) print(job.wait()) ``` # Arguments start_immediately (bool):
 #True if the factory should call #Job.start() immediately, #False if it should return the job in pending state. """


    def decorator(func):
      def wrapper(*args, **kwargs):
        job = Job(task=lambda j: func(j, *args, **kwargs))
        if start_immediately:
          job.start()
        return job
      return wrapper
    return decorator