Run feeds importer crons one after another I have two feeds importers. I wanted to run the 2nd importer when the first is finished.

I have written a cronapi hook for those two importers.

/**
 * Implements hook_cronapi().
 */
function mymodule_cronapi($op, $job = NULL) {
  $items = array(
    'cron_one' =&gt; array(
      'description' =&gt; 'import feeds one',
      'rule' =&gt; '4 0 * * *',
      'callback' =&gt; 'mymodule_import_feeds_one',
    ),
    'cron_2' =&gt; array(
      'description' =&gt; 'Import feeds two',
      'rule' =&gt; '4 0 * * *',
      'callback' =&gt; 'mymodule_import_feeds_two',
    ),
  );

  return $items;
}


In the hook_enable I am executing the first importer

function mymodule_enable() {
  mymodule_import_feeds_one();
}

function mymodule_import_feeds_one() {
  $src = feeds_source('import_feeds_one');
  $src-&gt;save();
  // Set the directory path.
  $source = 'directory-path';
  $config = array('FeedsFileFetcher' =&gt; array('source' =&gt; $source));
  $src-&gt;addConfig($config);
  $src-&gt;save();
  try {
    $src-&gt;import();
    $src-&gt;schedule();
  }
  catch (Exception $e) {
    return FALSE;
  }
  // Prevent notices from being thrown.
  $src-&gt;state(FEEDS_FETCH);
  $src-&gt;state(FEEDS_PROCESS);
  $src-&gt;state(FEEDS_PROCESS_CLEAR);

  return FALSE;
}


In hook_feeds_after_import

/**
 * Implements hook_feeds_after_import().
 */
function mymodule_feeds_after_import(FeedsSource $source) {
  if ($source-&gt;id == 'import_feeds_one') {

    mymodule_import_feeds_two();
  }
}


The problem is, when I enable the module, it schedules both importers on next cron run. 

I want to schedule only the first one and when the first one is completed then schedule the 2nd one.

How can I do that?
Your approach is already heading in the good direction. If you don't want to schedule the import of both importers, then you should only schedule the first one in mymodule_cronapi().

Then, in mymodule_feeds_after_import(), you'll schedule the next one by calling startImport() on the second source object (or by doing something similar as you did in mymodule_import_feeds_one()). If you configure your importer to import in the background, then startImport() will result into the source being imported during cron. If your import task is large, it may be divided in multiple chunks (depends on the implementation of the parser) so PHP wouldn't exceed the maximum runtime. In this case the import may take multiple cron runs to complete.

/**
 * Implements hook_cronapi().
 */
function mymodule_cronapi($op, $job = NULL) {
  $items = array(
    'cron_one' =&gt; array(
      'description' =&gt; 'import feeds one',
      'rule' =&gt; '4 0 * * *',
      'callback' =&gt; 'mymodule_import_feeds_one',
    ),
  );

  return $items;
}

/**
 * Implements hook_feeds_after_import().
 */
function mymodule_feeds_after_import(FeedsSource $source) {
  if ($source-&gt;id == 'import_feeds_one') {

    feeds_source('import_feeds_two')-&gt;existing()-&gt;startImport();
  }
}


I'm not sure why you want to start an import in mymodule_enable(). This code is only called once, when enabling your custom module (unless you disable the module and enable it again).