Question

Is it possible to create several batches at one time?

For example I have a code that has a running batch (batch 1). And inside this batch I have a method called which has another batch inside it (batch 2). The code is not working.

When I remove the upper batch (batch 1) I have a created node. Maybe there is only 1 batch possible at one time?

The example code is below:

$batch = $client->startBatch();

$widget = NULL;

try {
    $widgetLabel = $client->makeLabel('Widget');

    $widget = $client->makeNode();
    $widget
        ->setProperty('base_filename', md5(uniqid('', TRUE)))
        ->setProperty('datetime_added', time())
        ->setProperty('current_version', 0)
        ->setProperty('shared', 0)
        ->setProperty('active', 1)
    ->save();

    // add widget history
    $history = Model_History::create($widget, $properties);

    if ($history == NULL) {
        throw new Exception('Could not create widget history!');
    }

    $widget->setProperty('current_version', $history->getID());
    $widget->save();

    $client->commitBatch($batch);
} catch (Exception $e) {
    $client->endBatch();
}

The batch 2 is inside the Model_History::create() method. I don't get a valid $widget - Neo4jphp node from this code.

Was it helpful?

Solution

If the second batch is being create with another call to $client->startBatch() it will actually be the same batch object as $batch. If you call $client->commitBatch() from there, it will commit the outer batch (since they are the same.)

Don't start a second batch in Model_History::create(). Start the outer batch, go through all your code, and commit it once at the end.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top