How to use Heroku Worker workstations with custom clocks with PHP programs?

I am new to Heroku. I am trying to achieve something simple (at least I hope), but there seems to be no direct way to do this.

I have a couple of PHP files that I try to run as a scheduled task (every 5 minutes). These runs may take more than 30 seconds several times. Therefore, as I understand it, I need to install them as workplaces.

The Heroku example seems like a complicated example from which I could not figure out how an existing PHP file should be marked as working.

In addition, I would like to schedule this work task to run every 5 minutes. The docs are for custom watches, but there is no example for PHP.

Can someone point me to a tutorial on how to use workflows and plan their Heroku for PHP programs? Something a newbie might follow.

Thank!

+8
source share
3 answers

The work of the watch process in this case is to call some other piece of code, let's call it a scheduler , with a regular periodic interval. As an argument, let's say that our scheduler will wait for a call every minute. This is how Laravella's scheduler is set up and, therefore, the Heroka clock that I use (and wrote).

? , . - . , . , . ( - !).

heroku , clock: php artisan clock. Laravel. php, .

? , , , , .

? , (, , 14:00 ..). , , , , , : "- ?". - , ( dyno / , , ), : " " ., .

, OP php laravel, , laravel, , . laravel. , , , , . . - cron, . Heroku , - .

, , , - php-, ( heroku, Procfile, , ) ( procfile, t ), , , , , , $this->call('schedule:run') , , $this->call('schedule:run'), . , , , .

, , , !

( ). , , Procfile .

while(true) {
  if (now()->second <= 10)  // "runnable window"
  {
      $this->call('schedule:run');
      sleep(4);             // "min. duration"
  } 
  sleep(7);                 // "polling delay"
}

, , , , . , / 30 . , , ( heroku), , .

, . , , . , 10 dyno. , , 10 . , , ( ), , . , . , - . , , , , . , , ! , , . , , , , , , . , - , .

, OP, "", , , , , , " , ', , . , , .

+1

:

  • Heroku;
  • Heroku Scheduler ( heroku addons:create scheduler:standard --app <yourAppName>);
  • :

enter image description here

.

+1

clock.py :

from apscheduler.schedulers.blocking import BlockingScheduler
import os
import sys
import logging

logging.basicConfig(stream=sys.stdout,level=logging.INFO)

logging.info('clock init')

sched = BlockingScheduler()

@sched.scheduled_job('interval', minutes=1)
def timed_job():
    //logging.info('log message')
    //use this if you want to run console command
    os.system("php bin/console app:check-feedback")
    //or
    //whatever you want to run that every 1 minutes 

sched.start()

.txt :

APScheduler==3.0.0

Procfile:

clock: python clock.py

Run this heroku command

$heroku buildpacks:add --index 2 heroku/python

OR add an extra python buildpack to your dyno in the Heroku> app> toolbar settings:

enter image description here

Expand the app. Finally, add dyno to your watchmaking process:

$heroku ps:scale clock=1

Check your logs:

$heroku logs --tail
-3
source

All Articles