Hi,

Why don't you rely on job scheduler API (https://drupal.org/project/job_scheduler) ?

I find quite messy having feeds + job scheduler + scheduler.

At my sens, it's nice to have an API like job scheduler. Scheduler should be just a module for end-users to help them administrate nodes schedules, etc.

Cheers

Comments

jonathan1055’s picture

Hi lahode

Thanks for your comments and your interest in Scheduler. Job Scheduler is quite new (only existed since 6.x, for a bit over three years, Sept 2010) whereas Scheduler has been here for more than ten years (it was started in 2003 on 4.x) before Job Scheduler API was even thought of. As far as I know there was no discussion at the time when Job Scheduler API was being written as to how best to integrate/re-use/merge the modules.

Maybe you would like to put together a proper case for making this change, and we could consider it for D8. I would very much doubt we'd make such a big change within the D7 version. But if you convince us to investigate it further we will. There would have to be a very good fit of functionality and clear benefits for users and developers, not just a 'I find quite messy having feeds + job scheduler + scheduler' comment ;-)

Jonathan

lahode’s picture

You're right, my comment is silly :)

I looked the code of your module, and I thing 1/3 of it could just disappear, the most complex one.

A nice advantage too, is that job schedule can run process periodically, imagine a news that should appear every month for instance.

Finally, by simplifying your code, it should be easier to adapt your module not only for nodes, but entities, which is in Drupal 7 or 8 very interesting

For your information: http://www.computerminds.co.uk/drupal-code/easily-scheduling-periodic-ta... shows that with a few lines, you can do magic

A rough idea:

function scheduler_entity_publish() {
  ...
}

function scheduler_entity_unpublish() {
  ...
}

function weekly_task_cron_job_scheduler_info() {
  $info = array();
  $info['scheduler_entity_publish'] = array(
    'worker callback' => 'scheduler_entity_publish',
  );
  $info['scheduler_entity_publish'] = array(
    'worker callback' => 'scheduler_entity_unpublish',
  );
  return $info;
}

function scheduler_entity_update($entity, $type) {
  $info = entity_get_info($type);
  if ($entity->publish_on) {
    $job = array(
      'name' => 'publish|' . $type . '|' . $info->bundle . '|' . $entity->id,
      'type' => 'scheduler_job',
      'period' => $node->schedule_period,
      'crontab' => '0 0 * * 0',
      'periodic' => $node->schedule_period ? TRUE : FALSE,
    );
    JobScheduler::get('scheduler_entity_publish')->set($job);
  }
  if ($entity->unpublish_on) {
    $job = array(
      'name' => 'unpublish|' . $type . '|' . $info->bundle . '|' . $entity->id,
      'type' => 'scheduler_job',
      'period' => $node->schedule_period,
      'crontab' => '0 0 * * 0',
      'periodic' => $node->schedule_period ? TRUE : FALSE,
    );
    JobScheduler::get('scheduler_entity_unpublish')->set($job);    
  }
}

Have a nice day

jonathan1055’s picture

jonathan1055’s picture

Status: Active » Closed (won't fix)

I think it is time this issue was closed.
Also see #8 in #915492-8: Support of Job Scheduler and Queue API for better scaling