當前位置: 首頁>>代碼示例>>Python>>正文


Python Job.get方法代碼示例

本文整理匯總了Python中mrq.job.Job.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Job.get方法的具體用法?Python Job.get怎麽用?Python Job.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mrq.job.Job的用法示例。


在下文中一共展示了Job.get方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_interrupt_worker_gracefully

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_interrupt_worker_gracefully(worker, p_flags):
    """ Test what happens when we interrupt a running worker gracefully. """

    worker.start(flags=p_flags)

    job_id = worker.send_task(
        "tests.tasks.general.Add", {"a": 41, "b": 1, "sleep": 5}, block=False)

    time.sleep(2)

    job = Job(job_id).fetch().data
    assert job["status"] == "started"

    # Stop the worker gracefully. first job should still finish!
    worker.stop(block=False, deps=False)

    time.sleep(1)

    # Should not be accepting new jobs!
    job_id2 = worker.send_task(
        "tests.tasks.general.Add", {"a": 42, "b": 1, "sleep": 4}, block=False)

    time.sleep(1)

    job = Job(job_id2).fetch().data
    assert job.get("status") == "queued"

    time.sleep(4)

    job = Job(job_id).fetch().data
    assert job["status"] == "success"
    assert job["result"] == 42

    job = Job(job_id2).fetch().data
    assert job.get("status") == "queued"
開發者ID:iorlas,項目名稱:mrq,代碼行數:37,代碼來源:test_interrupts.py

示例2: wait_for_tasks_results

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
  def wait_for_tasks_results(self, job_ids, block=True, accept_statuses=["success"]):

    if not block:
      return job_ids

    results = []

    for job_id in job_ids:
      job = Job(job_id).wait(poll_interval=0.01)
      assert job.get("status") in accept_statuses, "Job had status %s, not in %s. Dump: %s" % (job.get("status"), accept_statuses, job)

      results.append(job.get("result"))

    return results
開發者ID:bossjones,項目名稱:mrq,代碼行數:16,代碼來源:conftest.py

示例3: test_cancel_by_path

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_cancel_by_path(worker):

  # Start the worker with only one greenlet so that tasks execute sequentially
  worker.start(flags="--gevent 1")

  job_id1 = worker.send_task("tests.tasks.general.MongoInsert", {"a": 41, "sleep": 2}, block=False)

  worker.send_task("mrq.basetasks.utils.JobAction", {
    "path": "tests.tasks.general.MongoInsert",
    "status": "queued",
    "action": "cancel"
  }, block=False)

  job_id2 = worker.send_task("tests.tasks.general.MongoInsert", {"a": 43}, block=False)

  Job(job_id2).wait(poll_interval=0.01)

  # Leave some time to unqueue job_id2 without executing.
  time.sleep(1)
  worker.stop(deps=False)

  job1 = Job(job_id1).fetch().data
  job2 = Job(job_id2).fetch().data

  assert job1["status"] == "success"
  assert job1["result"] == {"a": 41, "sleep": 2}

  assert job2["status"] == "cancel"
  assert job2["dateexpires"] > job2["dateupdated"]

  assert job2.get("result") is None

  assert worker.mongodb_logs.tests_inserts.count() == 1

  assert Queue("default").size() == 0
開發者ID:bossjones,項目名稱:mrq,代碼行數:37,代碼來源:test_cancel.py

示例4: test_interrupt_worker_double_sigint

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_interrupt_worker_double_sigint(worker, p_flags):
    """ Test what happens when we interrupt a running worker with 2 SIGINTs. """

    start_time = time.time()

    worker.start(flags=p_flags)

    job_id = worker.send_task("tests.tasks.general.Add", {"a": 41, "b": 1, "sleep": 20}, block=False)

    while Job(job_id).fetch().data["status"] == "queued":
        time.sleep(0.1)

    job = Job(job_id).fetch().data
    assert job["status"] == "started"

    # Stop the worker gracefully. first job should still finish!
    worker.stop(block=False, deps=False)

    time.sleep(1)

    # Should not be accepting new jobs!
    job_id2 = worker.send_task("tests.tasks.general.Add", {"a": 42, "b": 1, "sleep": 20}, block=False)

    time.sleep(1)

    job2 = Job(job_id2).fetch().data
    assert job2.get("status") == "queued"

    job = Job(job_id).fetch().data
    assert job["status"] == "started"

    # Sending a second kill -2 should make it stop
    worker.stop(block=True, deps=False, force=True)

    while Job(job_id).fetch().data["status"] == "started":
        time.sleep(0.1)

    job = Job(job_id).fetch().data
    assert job["status"] == "interrupt"

    assert time.time() - start_time < 15

    # Then try the cleaning task that requeues interrupted jobs

    assert Queue("default").size() == 1

    worker.start(queues="cleaning", deps=False, flush=False)

    res = worker.send_task("mrq.basetasks.cleaning.RequeueInterruptedJobs", {}, block=True, queue="cleaning")

    assert res["requeued"] == 1

    assert Queue("default").size() == 2

    Queue("default").list_job_ids() == [str(job_id2), str(job_id)]

    job = Job(job_id).fetch().data
    assert job["status"] == "queued"
    assert job["queue"] == "default"
開發者ID:pricingassistant,項目名稱:mrq,代碼行數:61,代碼來源:test_interrupts.py

示例5: test_retry

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_retry(worker):

  job_id = worker.send_task("mrq.basetasks.tests.general.Retry", {"queue": "noexec", "countdown": 60}, block=False)

  job_data = Job(job_id).wait(poll_interval=0.01, full_data=True)

  assert job_data["queue"] == "noexec"
  assert job_data["status"] == "retry"
  assert job_data["dateretry"] > datetime.datetime.utcnow()
  assert job_data.get("result") is None
開發者ID:nfredrik,項目名稱:mrq,代碼行數:12,代碼來源:test_retry.py

示例6: test_retry_cancel_on_retry

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_retry_cancel_on_retry(worker):

  job_id = worker.send_task("mrq.basetasks.tests.general.Retry", {
    "queue": "noexec",
    "countdown": 60,
    "cancel_on_retry": True
  }, block=False)

  job_data = Job(job_id).wait(poll_interval=0.01, full_data=True)

  assert job_data["status"] == "cancel"
  assert job_data["queue"] == "default"
  assert job_data.get("result") is None
開發者ID:nfredrik,項目名稱:mrq,代碼行數:15,代碼來源:test_retry.py

示例7: test_interrupt_maxconcurrency

# 需要導入模塊: from mrq.job import Job [as 別名]
# 或者: from mrq.job.Job import get [as 別名]
def test_interrupt_maxconcurrency(worker):

    # The worker will raise a maxconcurrency on the second job
    worker.start(flags="--greenlets=2")

    job_ids = worker.send_tasks(
        "tests.tasks.concurrency.LockedAdd", [{"a": i, "b": 1, "sleep": 2} for i in range(2)], block=False
    )

    worker.wait_for_tasks_results(job_ids, accept_statuses=["success", "failed", "maxconcurrency"])
    job_statuses = [Job(job_id).fetch().data["status"] for job_id in job_ids]
    assert set(job_statuses) == set(["success", "maxconcurrency"])

    # the job concurrency key must be equal to 0
    last_job_id = worker.send_task("tests.tasks.concurrency.LockedAdd", {"a": 1, "b": 1, "sleep": 2}, block=False)

    last_job = Job(last_job_id).wait(poll_interval=0.01)
    assert last_job.get("status") == "success"
開發者ID:pricingassistant,項目名稱:mrq,代碼行數:20,代碼來源:test_interrupts.py


注:本文中的mrq.job.Job.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。