function generateSpriteForCluster($clusterIdentifier, SpriteTool $spriteTool, $backupExisting = true, $includeTimestamp = true)
{
    $response = $spriteTool->generateSpriteForCluster($clusterIdentifier, $backupExisting, $includeTimestamp);
    if ($response['errorCode'] != 0) {
        throw new \Exception($response['error'], $response['errorCode']);
    }
}
if ($env != 'stg')
{
    eZCLI::instance()->output('This cronjob will only work on stg env');
    eZExecution::cleanExit();
}

$db = eZDB::instance();

/* regenerate sprite for only pending clusters */
$sql = "SELECT distinct(param)
           FROM ezpending_actions
           WHERE action = 'generate_app_sprite'";


$actions = $db->arrayQuery( $sql );

if (empty($actions))
{
    eZExecution::cleanExit();
}

$spriteTool = new SpriteTool();
foreach ( $actions as $action )
{
    $result = $spriteTool->generateSpriteForCluster( $action['param'] );
    if ($result['errorCode'] == 0)
    {
        $sql = sprintf( "DELETE FROM ezpending_actions WHERE action = 'generate_app_sprite' AND param = '%s'", $action['param'] );
        $db->query( $sql );
    }
}