Esempio n. 1
0
    def test_result_set_error(self, manager):
        assert_ping(manager)

        rs = ResultSet([raise_error.delay(), add.delay(1, 1)])
        rs.get(timeout=TIMEOUT, propagate=False)

        assert rs.results[0].failed()
        assert rs.results[1].successful()
Esempio n. 2
0
    def test_result_set_error(self, manager):
        assert manager.inspect().ping()

        rs = ResultSet([raise_error.delay(), add.delay(1, 1)])
        rs.get(timeout=TIMEOUT, propagate=False)

        assert rs.results[0].failed()
        assert rs.results[1].successful()
Esempio n. 3
0
    def test_result_set_error(self, manager):
        assert list(manager.inspect().ping().values())[0] == {"ok": "pong"}

        rs = ResultSet([raise_error.delay(), add.delay(1, 1)])
        rs.get(timeout=TIMEOUT, propagate=False)

        assert rs.results[0].failed()
        assert rs.results[1].successful()
Esempio n. 4
0
 def test_get(self):
     x = ResultSet(map(AsyncResult, [1, 2, 3]))
     b = x.results[0].backend = Mock()
     b.supports_native_join = False
     x.join_native = Mock()
     x.join = Mock()
     x.get()
     self.assertTrue(x.join.called)
     b.supports_native_join = True
     x.get()
     self.assertTrue(x.join_native.called)
Esempio n. 5
0
 def test_get(self):
     x = ResultSet(map(AsyncResult, [1, 2, 3]))
     b = x.results[0].backend = Mock()
     b.supports_native_join = False
     x.join_native = Mock()
     x.join = Mock()
     x.get()
     self.assertTrue(x.join.called)
     b.supports_native_join = True
     x.get()
     self.assertTrue(x.join_native.called)
Esempio n. 6
0
def getHashes(roms):
    resultSet = ResultSet([])
    for rom in roms:
        # Need the full path for the MD5 hash function to operate on the file
        fullPath = settings.ROMS_FOLDER + "/" + rom['filename']
        resultSet.add(getMD5Hash.delay(fullPath))
    return resultSet.get()
Esempio n. 7
0
 def end(self):
     """Do the push once all results are in"""
     dbg("Waiting for %d celery task(s)..." % len(self.results))
     result_set = ResultSet(self.results)
     results = result_set.get(
         timeout=self.context.get("timeout", None),
         propagate=self.context.get("propagate", True),
         interval=self.context.get("interval", 0.5),
     )
     result_set.forget()
     if results and self.context.get("flatten", False):
         results = flatten(results)
     self.push(results)
Esempio n. 8
0
def convert_file(is_video, input_path, output_format, video_length,
                 part_length):
    rs = ResultSet([])

    for i in range(get_total_workers()):
        start_at = i * part_length
        stop_at = start_at + part_length if i != get_total_workers(
        ) - 1 else video_length
        print("worker {} will process from {}s to {}s".format(
            i + 1, start_at, stop_at))
        rs.add(
            process_part.delay(is_video, input_path, output_format, start_at,
                               stop_at))

    return rs.get()
Esempio n. 9
0
    def obj_get_list(self, bundle, **kwargs):
        query = bundle.request.GET.get('q')
        if not query:
            response = {'status': 0, 'message': 'Empty query'}
        else:
            #from my_task.tasks import google, duck_duck_go, twitter
            from my_task.tasks import google, duck_duck_go, twitter

            # Async process
            from celery.result import ResultSet

            #A collection of results.
            rs = ResultSet([])

            # Add AsyncResult as a new member of the set.

            rs.add(google.delay(query))
            rs.add(duck_duck_go.delay(query))
            rs.add(twitter.delay(query))
            response = rs.get()  # waiting for the results
            url = "http://127.0.0.1:8000/my_resources/v1/search/?q={query}".format(
                query=query)
            try:
                response = {
                    'query': query,
                    'results': {
                        'google': {
                            'text': response[0],
                            'url': url
                        },
                        'duckduckgo': {
                            'text': response[1],
                            'url': url
                        },
                        'twitter': {
                            'text': response[2],
                            'url': url
                        }
                    }
                }
            except AttributeError:
                response = {'status': 0, 'message': 'Result Timeout'}

        # For immediate response
        raise ImmediateHttpResponse(response=HttpCreated(
            content=json.dumps(response),
            content_type='application/json; charset=UTF-8'))
Esempio n. 10
0
    def test_result_set(self, manager):
        assert_ping(manager)

        rs = ResultSet([add.delay(1, 1), add.delay(2, 2)])
        assert rs.get(timeout=TIMEOUT) == [2, 4]
Esempio n. 11
0
def get_check_prime(minimum, maximum):
    data = range(int(minimum), int(maximum))
    chunks = [data[x:x + CHUNK_SIZE] for x in xrange(0, len(data), CHUNK_SIZE)]
    results = ResultSet(map(is_prime, chunks))
    result = sum(results.get(), [])
    return json.dumps([x[0] for x in result if x[1]])
Esempio n. 12
0
    cwd = os.getcwd()
    print(cwd)

    graph = "power_law"
    indep = False
    pEFoI = (1 / 5000) / 2
    n_samp = 500

    if indep == True: 
        cor_or_not = "Uncorr"
    else: 
        cor_or_not = "Corr"

    if pEFoI == (1 / 5000) / 2: 
        lvl = "Low"
    else: 
        lvl = "High"


    start_time = time.time()
    ret = ResultSet([sim_task.delay(i, indep, graph, pEFoI) for i in range(n_samp)])
    print(len(ret.get()))
    end_time = time.time()
    print("CeleryTime:", end_time - start_time)

    with open('results/RRresults/trend/' + graph + cor_or_not + lvl + '.txt', 'w') as fout:
        json.dump(ret.get(), fout)

    # with open('results/netout/netout_' + graph + cor_or_not + '.txt', 'w') as fout:
    #     json.dump(ret.get(), fout)
Esempio n. 13
0
    def test_result_set(self, manager):
        assert manager.inspect().ping()

        rs = ResultSet([add.delay(1, 1), add.delay(2, 2)])
        assert rs.get(timeout=TIMEOUT) == [2, 4]
Esempio n. 14
0
import time
from utils import check_website
from websites import WEBSITE_LIST

from celery import Celery 
from celery.result import ResultSet

app = Celery('celery_squirrel',
			 broker='redis://localhost:6379/0',
			 backend='redis://localhost:6379/0')


@app.task
def check_website_task(website):
	return check_website(website)

if __name__ == '__main__':
	start_time = time.time()

	#Using delay runs the task aysnc
	rs = ResultSet([check_website_task.delay(address) for address in WEBSITE_LIST])

	#Wait for the task to finish
	rs.get()

	end_time = time.time()

	print 'Celery Squirrel=',end_time-start_time
Esempio n. 15
0
    def test_result_set(self, manager):
        assert list(manager.inspect().ping().values())[0] == {"ok": "pong"}

        rs = ResultSet([add.delay(1, 1), add.delay(2, 2)])
        assert rs.get(timeout=TIMEOUT) == [2, 4]
Esempio n. 16
0
def get_check_prime(minimum, maximum):
    data = range(int(minimum), int(maximum))
    chunks = [data[x:x+CHUNK_SIZE] for x in xrange(0, len(data), CHUNK_SIZE)]
    results = ResultSet(map(is_prime, chunks))
    result = sum(results.get(), [])
    return json.dumps([x[0] for x in result if x[1]])