Comments (4)
Closing in favor of #93
from jobby.
Hi, I know this issue is already closed, but I face the same is issue from the jobby-pdo example https://github.com/jobbyphp/jobby/blob/master/resources/jobby-pdo.php
➜ cp vendor/hellogerard/jobby/resources/jobby-pdo.php .
➜ nano jobby-pdo.php # update autoload.php path
➜ php70 jobby-pdo.php
PHP Notice: Serialization of closure failed: The file containing the closure, "/home/arie/proj/Task/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(210) : eval()'d code" did not exist. in /home/arie/proj/Task/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php on line 116
my environments: PHP 7.0.31 on Linux
from jobby.
@ariews Did you attempt the solution in #93 (comment)?
from jobby.
yes, I tried to add require_once __DIR__.'/vendor/autoload.php
to the closure, but no luck.
I Just copied the jobby example, and update the vendor/autoload.php path, and adding vendor/autoload.php on closure. here is the file:
<?php
//
// This script demonstrates how to use jobby with a PDO-backend, which is used to
// save the jobby-cronjob/jobbies configuration.
//
// Adapt this file to your needs, copy it to your project-root,
// and add this line to your crontab file:
//
// * * * * * cd /path/to/project && php jobby-pdo.php 1>> /dev/null 2>&1
//
# update path
require_once __DIR__ . '/vendor/autoload.php';
// The table, which shall contain the cronjob-configuration(s).
$dbhJobbiesTableName = 'jobbies';
/*
* For demo-purposes, an in-memory SQLite database is used.
*
* !!! REPLACE WITH YOUR OWN DATASOURCE!!!
*/
$dbh = new PDO('sqlite::memory:');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*
* Setup a test-fixture, having two jobs, first one is a system-cmd (date), second one is a Closure
* (which is saved to pdo-database).
*/
$dbh->exec("
CREATE TABLE IF NOT EXISTS `$dbhJobbiesTableName`
(`name` VARCHAR(255) NOT NULL ,
`command` TEXT NOT NULL ,
`schedule` VARCHAR(255) NOT NULL ,
`mailer` VARCHAR(255) NULL DEFAULT 'sendmail' ,
`maxRuntime` INT UNSIGNED NULL ,
`smtpHost` VARCHAR(255) NULL ,
`smtpPort` SMALLINT UNSIGNED NULL ,
`smtpUsername` VARCHAR(255) NULL ,
`smtpPassword` VARCHAR(255) NULL ,
`smtpSender` VARCHAR(255) NULL DEFAULT 'jobby@localhost' ,
`smtpSenderName` VARCHAR(255) NULL DEFAULT 'Jobby' ,
`smtpSecurity` VARCHAR(20) NULL ,
`runAs` VARCHAR(255) NULL ,
`environment` TEXT NULL ,
`runOnHost` VARCHAR(255) NULL ,
`output` VARCHAR(255) NULL ,
`dateFormat` VARCHAR(100) NULL DEFAULT 'Y-m-d H:i:s' ,
`enabled` BOOLEAN NULL DEFAULT TRUE ,
`haltDir` VARCHAR(255) NULL , `debug` BOOLEAN NULL DEFAULT FALSE ,
PRIMARY KEY (`name`)
)
");
$insertCronJobConfiguration = $dbh->prepare("
INSERT INTO `$dbhJobbiesTableName`
(`name`,`command`,`schedule`,`output`)
VALUES
(:name,:command,:schedule,:output)
");
// First demo-job - print "date" to logs/command-pdo.log.
$insertCronJobConfiguration->execute(
['CommandExample', 'date', '* * * * *', 'logs/command-pdo.log']
);
// Second demo-job - a Closure which does some php::echo(). The Closure is saved to PDO-backend, too.
$secondJobFn = function() {
# add autoload
require_once __DIR__ . '/vendor/autoload.php';
echo "I'm a function (" . date('Y-m-d H:i:s') . ')!' . PHP_EOL;
return true;
};
$serializer = new SuperClosure\Serializer();
$secondJobFnSerialized = $serializer->serialize($secondJobFn);
$insertCronJobConfiguration->execute(
['ClosureExample', $secondJobFnSerialized, '* * * * *', 'logs/closure-pdo.log']
);
/*
* Examples are now set up, and saved to PDO-backend.
*
* Now, fetch all jobbies from PDO-backend and run them.
*/
$jobbiesStmt = $dbh->query("SELECT * FROM `$dbhJobbiesTableName`");
$jobbies = $jobbiesStmt->fetchAll(PDO::FETCH_ASSOC);
$jobby = new \Jobby\Jobby();
foreach ($jobbies as $job) {
// Filter out each value, which is not set (for example, "maxRuntime" is not defined in the job).
$job = array_filter($job);
try {
$job['closure'] = $serializer->unserialize($job['command']);
unset($job['command']);
} catch (SuperClosure\Exception\ClosureUnserializationException $e) {
}
$jobName = $job['name'];
unset($job['name']);
$jobby->add($jobName, $job);
}
$jobby->run();
if you are curious about the modules:
➜ php70 -m
[PHP Modules]
apcu
Core
ctype
curl
date
dom
fileinfo
filter
gd
hash
iconv
imagick
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
readline
redis
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib
[Zend Modules]
from jobby.
Related Issues (20)
- DateTimeImmutable and PHP Version HOT 1
- possibility to change lockfile location HOT 2
- is there any way to kill all jobs running in jobby at a point of time? HOT 2
- how i can run in cloud foundry buildpack
- two jobs be executed at the same minute
- Not executing with Symfony Process 3.3.6
- How to build it from source
- Check if a cron is enabled or not? HOT 1
- Package mtdowling/cron-expression is abandoned
- run command using zsh or bash shell? HOT 2
- Is this project abandoned? HOT 2
- Question: How can I get a persistent jobby logfile
- Not working with Symfony Process 5.1.2 on PHP 7.3
- Adding 'nice' process priority parameter to jobs
- Extract Swift mailer capability to new package HOT 6
- Warning: exec() has been disabled for security reasons
- Does this library support catch-up like anacron/fcron?
- Does this library support system load average thresholds like fcron?
- putting the lck file outside the server ( redis or mysql / GCP, AWS)
- Parameter to set location of debug.log
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jobby.