From 571b85dc7e286adc5662e790d484d76f854c9182 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 8 Aug 2019 00:52:27 +0900 Subject: [PATCH 01/19] switch to Minilla --- .gitignore | 9 +- Build.PL | 50 +---- CHANGES => Changes | 2 + LICENSE | 378 ++++++++++++++++++++++++++++++++++++ MANIFEST | 58 ------ MANIFEST.SKIP | 55 ------ META.json | 81 ++++++++ README.md | 354 ++++++++++++++++++++++++++++++--- cpanfile | 7 + minil.toml | 7 + {bin => script}/schwartzmon | 0 11 files changed, 819 insertions(+), 182 deletions(-) rename CHANGES => Changes (99%) create mode 100644 LICENSE delete mode 100644 MANIFEST delete mode 100644 MANIFEST.SKIP create mode 100644 META.json create mode 100644 cpanfile create mode 100644 minil.toml rename {bin => script}/schwartzmon (100%) diff --git a/.gitignore b/.gitignore index be1036b..a6cfb87 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,14 @@ cover_db/ TheSchwartz*.tar.gz MYMETA.yml MYMETA.json -META.json META.yml *.bak Notes.md +/TheSchwartz-* +/.build +/_build_params +/Build +/Build.bat +!Build/ +!META.json +!LICENSE diff --git a/Build.PL b/Build.PL index da21325..16855c4 100644 --- a/Build.PL +++ b/Build.PL @@ -1,46 +1,12 @@ -use 5.008; +# ========================================================================= +# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. +# DO NOT EDIT DIRECTLY. +# ========================================================================= + +use 5.008_001; use strict; -use warnings; -use Module::Build; -my $class = Module::Build->subclass( - class => 'My::Builder', - code => q{ - sub ACTION_authortest { - my ($self) = @_; - $self->test_files( qw< xt > ); - $self->recursive_test_files(1); - $self->depends_on('test'); - return; - } - sub ACTION_distdir { - my ($self) = @_; - $self->depends_on('authortest'); - return $self->SUPER::ACTION_distdir(); - } - } -); +use Module::Build::Tiny 0.035; -my $builder = $class->new( - module_name => 'TheSchwartz', - license => 'perl', - dist_author => 'Six Apart ', - dist_version_from => 'lib/TheSchwartz.pm', - configure_requires => { 'Module::Build' => 0 }, - build_requires => { - 'Module::Build' => 0, - 'Test::More' => 0, - 'Data::ObjectDriver' => 0.04, - 'Digest::MD5' => 0, - 'Storable' => 0, - }, - requires => { - 'Data::ObjectDriver' => 0.04, - 'Digest::MD5' => 0, - 'Storable' => 0, - }, - add_to_cleanup => [ 'TheSchwartz-*', 'tmp', 'blib', '*.bak', 'META.*' ], - script_files => ['bin/schwartzmon'], -); +Build_PL(); -$builder->create_build_script(); diff --git a/CHANGES b/Changes similarity index 99% rename from CHANGES rename to Changes index 582aca8..31b1562 100644 --- a/CHANGES +++ b/Changes @@ -1,3 +1,5 @@ +{{$NEXT}} + 1.12 Mon Mar 30 2015 - Fix replace_job hanging & postgresql issues. RT #65712 - Add strict_remove_ability to prevent auto resetting of abilities. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..32ffd2e --- /dev/null +++ b/LICENSE @@ -0,0 +1,378 @@ +This software is copyright (c) 2019 by , Six Apart Ltd, cpan@sixapart.com. All. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +Terms of the Perl programming language system itself + +a) the GNU General Public License as published by the Free + Software Foundation; either version 1, or (at your option) any + later version, or +b) the "Artistic License" + +--- The GNU General Public License, Version 1, February 1989 --- + +This software is Copyright (c) 2019 by , Six Apart Ltd, cpan@sixapart.com. All. + +This is free software, licensed under: + + The GNU General Public License, Version 1, February 1989 + + GNU GENERAL PUBLIC LICENSE + Version 1, February 1989 + + Copyright (C) 1989 Free Software Foundation, Inc. + 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The license agreements of most software companies try to keep users +at the mercy of those companies. By contrast, our General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. The +General Public License applies to the Free Software Foundation's +software and to any other program whose authors commit to using it. +You can use it for your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Specifically, the General Public License is designed to make +sure that you have the freedom to give away or sell copies of free +software, that you receive source code or can get it if you want it, +that you can change the software or use pieces of it in new free +programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of a such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must tell them their rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any program or other work which +contains a notice placed by the copyright holder saying it may be +distributed under the terms of this General Public License. The +"Program", below, refers to any such program or work, and a "work based +on the Program" means either the Program or any work containing the +Program or a portion of it, either verbatim or with modifications. Each +licensee is addressed as "you". + + 1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this +General Public License and to the absence of any warranty; and give any +other recipients of the Program a copy of this General Public License +along with the Program. You may charge a fee for the physical act of +transferring a copy. + + 2. You may modify your copy or copies of the Program or any portion of +it, and copy and distribute such modifications under the terms of Paragraph +1 above, provided that you also do the following: + + a) cause the modified files to carry prominent notices stating that + you changed the files and the date of any change; and + + b) cause the whole of any work that you distribute or publish, that + in whole or in part contains the Program or any part thereof, either + with or without modifications, to be licensed at no charge to all + third parties under the terms of this General Public License (except + that you may choose to grant warranty protection to some or all + third parties, at your option). + + c) If the modified program normally reads commands interactively when + run, you must cause it, when started running for such interactive use + in the simplest and most usual way, to print or display an + announcement including an appropriate copyright notice and a notice + that there is no warranty (or else, saying that you provide a + warranty) and that users may redistribute the program under these + conditions, and telling the user how to view a copy of this General + Public License. + + d) You may charge a fee for the physical act of transferring a + copy, and you may at your option offer warranty protection in + exchange for a fee. + +Mere aggregation of another independent work with the Program (or its +derivative) on a volume of a storage or distribution medium does not bring +the other work under the scope of these terms. + + 3. You may copy and distribute the Program (or a portion or derivative of +it, under Paragraph 2) in object code or executable form under the terms of +Paragraphs 1 and 2 above provided that you also do one of the following: + + a) accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of + Paragraphs 1 and 2 above; or, + + b) accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal charge + for the cost of distribution) a complete machine-readable copy of the + corresponding source code, to be distributed under the terms of + Paragraphs 1 and 2 above; or, + + c) accompany it with the information you received as to where the + corresponding source code may be obtained. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form alone.) + +Source code for a work means the preferred form of the work for making +modifications to it. For an executable file, complete source code means +all the source code for all modules it contains; but, as a special +exception, it need not include source code for modules which are standard +libraries that accompany the operating system on which the executable +file runs, or for standard header files or definitions files that +accompany that operating system. + + 4. You may not copy, modify, sublicense, distribute or transfer the +Program except as expressly provided under this General Public License. +Any attempt otherwise to copy, modify, sublicense, distribute or transfer +the Program is void, and will automatically terminate your rights to use +the Program under this License. However, parties who have received +copies, or rights to use copies, from you under this General Public +License will not have their licenses terminated so long as such parties +remain in full compliance. + + 5. By copying, distributing or modifying the Program (or any work based +on the Program) you indicate your acceptance of this license to do so, +and all its terms and conditions. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these +terms and conditions. You may not impose any further restrictions on the +recipients' exercise of the rights granted herein. + + 7. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of the license which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +the license, you may choose any version ever published by the Free Software +Foundation. + + 8. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to humanity, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + + To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19xx name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the +appropriate parts of the General Public License. Of course, the +commands you use may be called something other than `show w' and `show +c'; they could even be mouse-clicks or menu items--whatever suits your +program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + program `Gnomovision' (a program to direct compilers to make passes + at assemblers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +That's all there is to it! + + +--- The Artistic License 1.0 --- + +This software is Copyright (c) 2019 by , Six Apart Ltd, cpan@sixapart.com. All. + +This is free software, licensed under: + + The Artistic License 1.0 + +The Artistic License + +Preamble + +The intent of this document is to state the conditions under which a Package +may be copied, such that the Copyright Holder maintains some semblance of +artistic control over the development of the package, while giving the users of +the package the right to use and distribute the Package in a more-or-less +customary fashion, plus the right to make reasonable modifications. + +Definitions: + + - "Package" refers to the collection of files distributed by the Copyright + Holder, and derivatives of that collection of files created through + textual modification. + - "Standard Version" refers to such a Package if it has not been modified, + or has been modified in accordance with the wishes of the Copyright + Holder. + - "Copyright Holder" is whoever is named in the copyright or copyrights for + the package. + - "You" is you, if you're thinking about copying or distributing this Package. + - "Reasonable copying fee" is whatever you can justify on the basis of media + cost, duplication charges, time of people involved, and so on. (You will + not be required to justify it to the Copyright Holder, but only to the + computing community at large as a market that must bear the fee.) + - "Freely Available" means that no fee is charged for the item itself, though + there may be fees involved in handling the item. It also means that + recipients of the item may redistribute it under the same conditions they + received it. + +1. You may make and give away verbatim copies of the source form of the +Standard Version of this Package without restriction, provided that you +duplicate all of the original copyright notices and associated disclaimers. + +2. You may apply bug fixes, portability fixes and other modifications derived +from the Public Domain or from the Copyright Holder. A Package modified in such +a way shall still be considered the Standard Version. + +3. You may otherwise modify your copy of this Package in any way, provided that +you insert a prominent notice in each changed file stating how and when you +changed that file, and provided that you do at least ONE of the following: + + a) place your modifications in the Public Domain or otherwise make them + Freely Available, such as by posting said modifications to Usenet or an + equivalent medium, or placing the modifications on a major archive site + such as ftp.uu.net, or by allowing the Copyright Holder to include your + modifications in the Standard Version of the Package. + + b) use the modified Package only within your corporation or organization. + + c) rename any non-standard executables so the names do not conflict with + standard executables, which must also be provided, and provide a separate + manual page for each non-standard executable that clearly documents how it + differs from the Standard Version. + + d) make other distribution arrangements with the Copyright Holder. + +4. You may distribute the programs of this Package in object code or executable +form, provided that you do at least ONE of the following: + + a) distribute a Standard Version of the executables and library files, + together with instructions (in the manual page or equivalent) on where to + get the Standard Version. + + b) accompany the distribution with the machine-readable source of the Package + with your modifications. + + c) accompany any non-standard executables with their corresponding Standard + Version executables, giving the non-standard executables non-standard + names, and clearly documenting the differences in manual pages (or + equivalent), together with instructions on where to get the Standard + Version. + + d) make other distribution arrangements with the Copyright Holder. + +5. You may charge a reasonable copying fee for any distribution of this +Package. You may charge any fee you choose for support of this Package. You +may not charge a fee for this Package itself. However, you may distribute this +Package in aggregate with other (possibly commercial) programs as part of a +larger (possibly commercial) software distribution provided that you do not +advertise this Package as a product of your own. + +6. The scripts and library files supplied as input to or produced as output +from the programs of this Package do not automatically fall under the copyright +of this Package, but belong to whomever generated them, and may be sold +commercially, and may be aggregated with this Package. + +7. C or perl subroutines supplied by you and linked into this Package shall not +be considered part of this Package. + +8. The name of the Copyright Holder may not be used to endorse or promote +products derived from this software without specific prior written permission. + +9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +The End diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 8414a56..0000000 --- a/MANIFEST +++ /dev/null @@ -1,58 +0,0 @@ -bin/schwartzmon -Build.PL -CHANGES -doc/http-mappings.txt -doc/notes.txt -doc/schema-postgres.sql -doc/schema.sql -extras/check_schwartz -extras/perl-TheSchwartz.spec -extras/thetop -lib/TheSchwartz.pm -lib/TheSchwartz/Error.pm -lib/TheSchwartz/ExitStatus.pm -lib/TheSchwartz/FuncMap.pm -lib/TheSchwartz/Job.pm -lib/TheSchwartz/JobHandle.pm -lib/TheSchwartz/Worker.pm -MANIFEST This list of files -MANIFEST.SKIP -META.yml -perltidyrc -README.md -server/bin/schwartzd -server/doc/deps.txt -server/doc/protocol.txt -server/t/00-start-ping.t -server/t/01-insert-and-get.t -server/t/lib/testlib.pl -t/05-job-ctor.t -t/api.t -t/cleanup.t -t/client-time-unsync.t -t/coalesce.t -t/dead-dbs.t -t/declined.t -t/empty-db.t -t/evenly-distribute.t -t/fail-working-multiple.t -t/funcid.t -t/grab-race.t -t/grab_and_work_on.t -t/high-funcid-starvation.t -t/insert-and-do.t -t/lib/db-common.pl -t/parallel-workers.t -t/priority.t -t/replace-abort.t -t/replace-with.t -t/retry-delay.t -t/schema-sqlite.sql -t/scoreboard.t -t/server-time.t -t/unique.t -t/work-before-funcids-exist.t -xt/perlcritic.t -xt/pod-coverage.t -xt/pod-spelling.t -xt/pod.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP deleted file mode 100644 index 6190fd3..0000000 --- a/MANIFEST.SKIP +++ /dev/null @@ -1,55 +0,0 @@ -MANIFEST.bak -ts1.db -ts2.db -build-stamp -install-stamp -.shipit -svn-commit.tmp - -# Avoid version control files. -\bRCS\b -\bCVS\b -,v$ -\B\.svn\b -\B\.git\b -\B\.gitignore\b - -# Avoid Makemaker generated and utility files. -\bMANIFEST\.bak -\bMakefile$ -\bblib/ -\bMakeMaker-\d -\bpm_to_blib$ - -# Avoid Module::Build generated and utility files. -\bBuild$ -\b_build/ -^Notes.md$ -\bTheSchwartz-[\d\.\_]+ - -# Avoid temp and backup files. -~$ -\.old$ -\#$ -\b\.# -\.git/ -\cover_db/ -^MYMETA.*$ - -# Avoid Devel::Cover and Devel::CoverX::Covered files. -\bcover_db\b -\bcovered\b - -# Avoid temp and backup files. -~$ -\.old$ -\#$ -\b\.# -\.bak$ -\.tmp$ -\.# -\.rej$ -\.swp$ -\.swo$ - - diff --git a/META.json b/META.json new file mode 100644 index 0000000..274c69f --- /dev/null +++ b/META.json @@ -0,0 +1,81 @@ +{ + "abstract" : "reliable job queue", + "author" : [ + ", Six Apart Ltd, cpan@sixapart.com. All" + ], + "dynamic_config" : 0, + "generated_by" : "Minilla/v3.1.5, CPAN::Meta::Converter version 2.150010", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : 2 + }, + "name" : "TheSchwartz", + "no_index" : { + "directory" : [ + "t", + "xt", + "inc", + "share", + "eg", + "examples", + "author", + "builder" + ] + }, + "prereqs" : { + "configure" : { + "requires" : { + "Module::Build::Tiny" : "0.035" + } + }, + "develop" : { + "requires" : { + "Test::CPAN::Meta" : "0", + "Test::MinimumVersion::Fast" : "0.04", + "Test::PAUSE::Permissions" : "0.07", + "Test::Pod" : "1.41", + "Test::Spellunker" : "v0.2.7" + } + }, + "runtime" : { + "requires" : { + "Data::ObjectDriver" : "0.04", + "Digest::MD5" : "0", + "Storable" : "0", + "perl" : "5.008" + } + }, + "test" : { + "requires" : { + "Test::More" : "0" + } + } + }, + "release_status" : "unstable", + "resources" : { + "bugtracker" : { + "web" : "https://github.com/akiym/TheSchwartz/issues" + }, + "homepage" : "https://github.com/akiym/TheSchwartz", + "repository" : { + "type" : "git", + "url" : "git://github.com/akiym/TheSchwartz.git", + "web" : "https://github.com/akiym/TheSchwartz" + } + }, + "version" : "1.12", + "x_authority" : "cpan:AKIYM", + "x_contributors" : [ + "Akira Sawada ", + "Brad Fitzpatrick ", + "Jeff Fearn ", + "Jeff Fearn ", + "Six Apart Ltd. ", + "Takumi Akiyama " + ], + "x_serialization_backend" : "JSON::PP version 4.04", + "x_static_install" : 1 +} diff --git a/README.md b/README.md index 474577f..1f2e6f8 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,345 @@ -TheSchwartz -============= +# NAME -**TheSchwartz** is a reliable job queue system. Your application can put jobs into the system, and your worker processes can pull jobs from the queue atomically to perform. Failed jobs can be left in the queue to retry later. +TheSchwartz - reliable job queue -**Abilities** specify what jobs a worker process can perform. Abilities are the names of *TheSchwartz::Worker* subclasses, as in the synopsis: the *MyWorker* class name is used to specify that the worker script can perform the job. When using the *TheSchwartz* client's *work* functions, the class-ability duality is used to automatically dispatch to the proper class to do the actual work. +# SYNOPSIS -TheSchwartz clients will also prefer to do jobs for unused abilities before reusing a particular ability, to avoid exhausting the supply of one kind of job while jobs of other types stack up. + # MyApp.pm + package MyApp; -Some jobs with high set-up times can be performed more efficiently if a group of related jobs are performed together. TheSchwartz offers a facility to **coalesce** jobs into groups, which a properly constructed worker can find and perform at once. For example, if your worker were delivering email, you might store the domain name from the recipient's address as the coalescing value. The worker that grabs that job could then batch deliver all the mail for that domain once it connects to that domain's mail server. + sub work_asynchronously { + my %args = @_; -INSTALLATION ------------- + my $client = TheSchwartz->new( databases => $DATABASE_INFO ); + $client->insert('MyWorker', \%args); + } -Just follow the usual procedure: - perl Build.PL - ./Build - ./Build test - ./Build install + # myworker.pl + package MyWorker; + use base qw( TheSchwartz::Worker ); -If you want to install a private copy of this module-suite in your home directory, then you should try to produce the initial Makefile with something like this command: + sub work { + my $class = shift; + my TheSchwartz::Job $job = shift; - perl Build.PL PREFIX=~/perl + print "Workin' hard or hardly workin'? Hyuk!!\n"; -See perldoc perlmodinstall for more information on installing modules. + $job->completed(); + } -SUPPORT -------- + package main; -Just follow the usual procedure: + my $client = TheSchwartz->new( databases => $DATABASE_INFO ); + $client->can_do('MyWorker'); + $client->work(); - perl Build.PL - ./Build +# DESCRIPTION -Questions, bug reports, useful code bits, and suggestions for this module should just be sent to JFEARN@cpan.org or open a ticket in the [CPAN RT](https://rt.cpan.org//Dist/Display.html?Queue=TheSchwartz) +TheSchwartz is a reliable job queue system. Your application can put jobs into +the system, and your worker processes can pull jobs from the queue atomically +to perform. Failed jobs can be left in the queue to retry later. -AVAILABILITY -------- -The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit (http://www.perl.com/CPAN/) to find a CPAN site near you. +_Abilities_ specify what jobs a worker process can perform. Abilities are the +names of `TheSchwartz::Worker` sub-classes, as in the synopsis: the `MyWorker` +class name is used to specify that the worker script can perform the job. When +using the `TheSchwartz` client's `work` functions, the class-ability duality +is used to automatically dispatch to the proper class to do the actual work. -The source is available on github (https://github.com/jfearn/TheSchwartz), patches should be sent as pull requests against this repository. +TheSchwartz clients will also prefer to do jobs for unused abilities before +reusing a particular ability, to avoid exhausting the supply of one kind of job +while jobs of other types stack up. +Some jobs with high setup times can be performed more efficiently if a group of +related jobs are performed together. TheSchwartz offers a facility to +_coalesce_ jobs into groups, which a properly constructed worker can find and +perform at once. For example, if your worker were delivering email, you might +store the domain name from the recipient's address as the coalescing value. The +worker that grabs that job could then batch deliver all the mail for that +domain once it connects to that domain's mail server. + +# USAGE + +## `TheSchwartz->new( %args )` + +Optional members of `%args` are: + +- `databases` + + An arrayref of database information. TheSchwartz workers can use multiple + databases, such that if any of them are unavailable, the worker will search for + appropriate jobs in the other databases automatically. + + Each member of the `databases` value should be a hashref containing either: + + - `dsn` + + The database DSN for this database. + + - `user` + + The user name to use when connecting to this database. + + - `pass` + + The password to use when connecting to this database. + + or + + - `driver` + + A `Data::ObjectDriver::Driver::DBI` object. + + See note below. + +- `verbose` + + A value indicating whether to log debug messages. If `verbose` is a coderef, + it is called to log debug messages. If `verbose` is not a coderef but is some + other true value, debug messages will be sent to `STDERR`. Otherwise, debug + messages will not be logged. + +- `prioritize` + + A value indicating whether to utilize the job 'priority' field when selecting + jobs to be processed. If unspecified, jobs will always be executed in a + randomized order. + +- `floor` + + A value indicating the minimum priority a job needs to be for this worker to + perform. If unspecified all jobs are considered. + +- `batch_size` + + A value indicating how many jobs should be fetched from the DB for consideration. + +- `driver_cache_expiration` + + Optional value to control how long database connections are cached for in seconds. + By default, connections are not cached. To re-use the same database connection for + five minutes, pass driver\_cache\_expiration => 300 to the constructor. Improves job + throughput in cases where the work to process a job is small compared to the database + connection set-up and tear-down time. + +- `retry_seconds` + + The number of seconds after which to try reconnecting to apparently dead + databases. If not given, TheSchwartz will retry connecting to databases after + 30 seconds. + +- `strict_remove_ability` + + By default when work\_once does not find a job it will reset current\_abilities to + all\_abilities and look for a job. Setting this option will prevent work\_once from + resetting abilities if it can't find a job for the current capabilities. + +## `$client->list_jobs( %args )` + +Returns a list of `TheSchwartz::Job` objects matching the given arguments. The +required members of `%args` are: + +- `funcname` + + the name of the function or a reference to an array of functions + +- `run_after` + + the value you want to check <= against on the run\_after column + +- `grabbed_until` + + the value you want to check <= against on the grabbed\_until column + +- `coalesce_op` + + defaults to '=', set it to whatever you want to compare the coalesce field too + if you want to search, you can use 'LIKE' + +- `coalesce` + + coalesce value to search for, if you set op to 'LIKE' you can use '%' here, + do remember that '%' searches anchored at the beginning of the string are + much faster since it is can do a btree index lookup + +- `want_handle` + + if you want all your jobs to be set up using a handle. defaults to true. + this option might be removed, as you should always have this on a Job object. + +- `jobid` + + if you want a specific job you can pass in it's ID and if it's available it + will be listed. + +It is important to remember that this function does not lock anything, it just +returns as many jobs as there is up to amount of databases \* $client->{batch\_size} + +## `$client->lookup_job( $handle_id )` + +Returns a `TheSchwartz::Job` corresponding to the given handle ID. + +## `$client->set_verbose( $verbose )` + +Sets the current logging function to `$verbose` if it's a coderef. If not a +coderef, enables debug logging to `STDERR` if `$verbose` is true; otherwise, +disables logging. + +# POSTING JOBS + +The methods of TheSchwartz clients used by applications posting jobs to the +queue are: + +## `$client->insert( $job )` + +Adds the given `TheSchwartz::Job` to one of the client's job databases. + +## `$client->insert( $funcname, $arg )` + +Adds a new job with function name `$funcname` and arguments `$arg` to the queue. + +## `$client->insert_jobs( @jobs )` + +Adds the given `TheSchwartz::Job` objects to one of the client's job +databases. All the given jobs are recorded in _one_ job database. + +## `$client->set_prioritize( $prioritize )` + +Set the `prioritize` value as described in the constructor. + +## `$client->set_floor( $floor )` + +Set the `floorset_batch_size( $batch_size )` + +Set the `batch_sizeset_strict_remove_ability( $strict_remove_ability )` + +Set the `strict_remove_abilitycan_do( $ability )` + +Adds `$ability` to the list of abilities `$client` is capable of performing. +Subsequent calls to that client's `work` methods will find jobs requiring the +given ability. + +## `$client->work_once()` + +Find and perform one job `$client` can do. + +## `$client->work_until_done()` + +Find and perform jobs `$client` can do until no more such jobs are found in +any of the client's job databases. + +## `$client->work( [$delay] )` + +Find and perform any jobs `$client` can do, forever. When no job is available, +the working process will sleep for `$delay` seconds (or 5, if not specified) +before looking again. + +## `$client->work_on($handle)` + +Given a job handle (a scalar string) _$handle_, runs the job, then returns. + +## `$client->grab_and_work_on($handle)` + +Similar to [$client->work\_on($handle)](https://metacpan.org/pod/$client->work_on\($handle\)), except that the job will be grabbed +before being run. It guarantees that only one worker will work on it (at least +in the `grab_for` interval). + +Returns false if the worker could not grab the job, and true if the worker worked +on it. + +## `$client->find_job_for_workers( [$abilities] )` + +Returns a `TheSchwartz::Job` for a random job that the client can do. If +specified, the job returned matches one of the abilities in the arrayref +`$abilities`, rather than `$client`'s abilities. + +## `$client->find_job_with_coalescing_value( $ability, $coval )` + +Returns a `TheSchwartz::Job` for a random job for a worker capable of +`$ability` and with a coalescing value of `$coval`. + +## `$client->find_job_with_coalescing_prefix( $ability, $coval )` + +Returns a `TheSchwartz::Job` for a random job for a worker capable of +`$ability` and with a coalescing value beginning with `$coval`. + +Note the `TheSchwartz` implementation of this function uses a `LIKE` query to +find matching jobs, with all the attendant performance implications for your +job databases. + +## `$client->get_server_time( $driver )` + +Given an open driver _$driver_ to a database, gets the current server time from the database. + +# THE SCOREBOARD + +The scoreboards can be used to monitor what the TheSchwartz::Worker sub-classes are +currently working on. Once the scoreboard has been enabled in the workers with +`set_scoreboard` method the `thetop` utility (shipped with TheSchwartz distribution +in the `extras` directory) can be used to list all current jobs being worked on. + +## `$client->set_scoreboard( $dir )` + +Enables the scoreboard. Setting this to `1` or `on` will cause TheSchwartz to create +a scoreboard file in a location it determines is optimal. + +Passing in any other option sets the directory the TheSchwartz scoreboard directory should +be created in. For example, if you set this to `/tmp` then this would create a directory +called `/tmp/theschwartz` and a scoreboard file `/tmp/theschwartz/scoreboard.pid` in it +(where pid is the current process pid.) + +## `$client->scoreboard()` + +Returns the path to the current scoreboard file. + +## `$client->start_scoreboard()` + +Writes the current job information to the scoreboard file (called by the worker +in work\_safely before it actually starts working) + +## `$client->end_scoreboard()` + +Appends the current job duration to the end of the scoreboard file (called by +the worker in work\_safely once work has been completed) + +## `$client->clean_scoreboard()` + +Removes the scoreboard file (but not the scoreboard directory.) Automatically +called by TheSchwartz during object destruction (i.e. when the instance goes +out of scope) + +# PASSING IN AN EXISTING DRIVER + +You can pass in a existing `Data::Object::Driver::DBI` object which also allows you +to reuse exist Database handles like so: + + my $dbh = DBI->connect( $dsn, "root", "", { + RaiseError => 1, + PrintError => 0, + AutoCommit => 1, + } ) or die $DBI::errstr; + my $driver = Data::ObjectDriver::Driver::DBI->new( dbh => $dbh); + return TheSchwartz->new(databases => [{ driver => $driver }]); + +**Note**: it's important that the `RaiseError` and `AutoCommit` flags are +set on the handle for various bits of functionality to work. + +# COPYRIGHT, LICENSE & WARRANTY + +This software is Copyright 2007, Six Apart Ltd, cpan@sixapart.com. All +rights reserved. + +TheSchwartz is free software; you may redistribute it and/or modify it +under the same terms as Perl itself. + +TheSchwartz comes with no warranty of any kind. diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..57d0a56 --- /dev/null +++ b/cpanfile @@ -0,0 +1,7 @@ +requires 'Data::ObjectDriver', '0.04'; +requires 'Digest::MD5'; +requires 'Storable'; + +on test => sub { + requires 'Test::More'; +}; diff --git a/minil.toml b/minil.toml new file mode 100644 index 0000000..69b45a2 --- /dev/null +++ b/minil.toml @@ -0,0 +1,7 @@ +name = "TheSchwartz" +# badges = ["travis-ci.com"] +authority="cpan:AKIYM" + +module_maker="ModuleBuildTiny" +static_install = "auto" + diff --git a/bin/schwartzmon b/script/schwartzmon similarity index 100% rename from bin/schwartzmon rename to script/schwartzmon From 6a2c5c13fd1f1f957ad839468a98c3e46184a26d Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 8 Aug 2019 01:01:29 +0900 Subject: [PATCH 02/19] [PATCH] Tests fail without '.' in @INC (RT#124610) Co-authored-by: Kent Fredric --- t/api.t | 2 +- t/cleanup.t | 2 +- t/client-time-unsync.t | 2 +- t/coalesce.t | 2 +- t/dead-dbs.t | 2 +- t/declined.t | 2 +- t/empty-db.t | 2 +- t/evenly-distribute.t | 2 +- t/fail-working-multiple.t | 2 +- t/funcid.t | 2 +- t/grab-race.t | 2 +- t/grab_and_work_on.t | 2 +- t/high-funcid-starvation.t | 2 +- t/insert-and-do.t | 2 +- t/parallel-workers.t | 2 +- t/priority.t | 2 +- t/replace-abort.t | 2 +- t/replace-with.t | 2 +- t/retry-delay.t | 2 +- t/scoreboard.t | 2 +- t/server-time.t | 2 +- t/unique.t | 2 +- t/work-before-funcids-exist.t | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/t/api.t b/t/api.t index 9d4d177..fb9c7b2 100644 --- a/t/api.t +++ b/t/api.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 58 * 3; diff --git a/t/cleanup.t b/t/cleanup.t index 034dc59..f13f23f 100644 --- a/t/cleanup.t +++ b/t/cleanup.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 30; diff --git a/t/client-time-unsync.t b/t/client-time-unsync.t index fa19a85..fd10047 100644 --- a/t/client-time-unsync.t +++ b/t/client-time-unsync.t @@ -17,7 +17,7 @@ BEGIN { } no warnings 'redefine'; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 2; diff --git a/t/coalesce.t b/t/coalesce.t index b42f732..0c152f4 100644 --- a/t/coalesce.t +++ b/t/coalesce.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 14 * 3; diff --git a/t/dead-dbs.t b/t/dead-dbs.t index eee73a6..673f5b4 100644 --- a/t/dead-dbs.t +++ b/t/dead-dbs.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 6; diff --git a/t/declined.t b/t/declined.t index 8fca90d..78dca2f 100644 --- a/t/declined.t +++ b/t/declined.t @@ -1,7 +1,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => (5 + 21) * 3; diff --git a/t/empty-db.t b/t/empty-db.t index 17353cd..6fc9bc1 100644 --- a/t/empty-db.t +++ b/t/empty-db.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 9; diff --git a/t/evenly-distribute.t b/t/evenly-distribute.t index 56533f0..3fc9082 100644 --- a/t/evenly-distribute.t +++ b/t/evenly-distribute.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 12; diff --git a/t/fail-working-multiple.t b/t/fail-working-multiple.t index 3750fc7..94f07f7 100644 --- a/t/fail-working-multiple.t +++ b/t/fail-working-multiple.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 12; diff --git a/t/funcid.t b/t/funcid.t index f363791..60510ba 100644 --- a/t/funcid.t +++ b/t/funcid.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 24; diff --git a/t/grab-race.t b/t/grab-race.t index 1071362..efcdff8 100644 --- a/t/grab-race.t +++ b/t/grab-race.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 2; diff --git a/t/grab_and_work_on.t b/t/grab_and_work_on.t index 7f7628e..be99827 100644 --- a/t/grab_and_work_on.t +++ b/t/grab_and_work_on.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 27; diff --git a/t/high-funcid-starvation.t b/t/high-funcid-starvation.t index 8469e9d..c879049 100644 --- a/t/high-funcid-starvation.t +++ b/t/high-funcid-starvation.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 12; diff --git a/t/insert-and-do.t b/t/insert-and-do.t index f6cc9f9..662abbd 100644 --- a/t/insert-and-do.t +++ b/t/insert-and-do.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 26 * 3; diff --git a/t/parallel-workers.t b/t/parallel-workers.t index 1834041..5300385 100644 --- a/t/parallel-workers.t +++ b/t/parallel-workers.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 2; diff --git a/t/priority.t b/t/priority.t index b6e1208..3ce6c6e 100644 --- a/t/priority.t +++ b/t/priority.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => ( ( 31 * 3 ) + ( 16 * 3 ) + ( 12 * 3 ) ); diff --git a/t/replace-abort.t b/t/replace-abort.t index 86d70f0..252bfb0 100644 --- a/t/replace-abort.t +++ b/t/replace-abort.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 13; diff --git a/t/replace-with.t b/t/replace-with.t index f9e7978..6887988 100644 --- a/t/replace-with.t +++ b/t/replace-with.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 30; diff --git a/t/retry-delay.t b/t/retry-delay.t index 27c5663..fdda944 100644 --- a/t/retry-delay.t +++ b/t/retry-delay.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 24; diff --git a/t/scoreboard.t b/t/scoreboard.t index c19a9d8..bc197d0 100644 --- a/t/scoreboard.t +++ b/t/scoreboard.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use Test::More tests => 30; diff --git a/t/server-time.t b/t/server-time.t index 870ab8e..47ded3a 100644 --- a/t/server-time.t +++ b/t/server-time.t @@ -3,7 +3,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 6; diff --git a/t/unique.t b/t/unique.t index f0bcea5..e013a32 100644 --- a/t/unique.t +++ b/t/unique.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 18; diff --git a/t/work-before-funcids-exist.t b/t/work-before-funcids-exist.t index 9c06e43..17efbbc 100644 --- a/t/work-before-funcids-exist.t +++ b/t/work-before-funcids-exist.t @@ -4,7 +4,7 @@ use strict; use warnings; -require 't/lib/db-common.pl'; +require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 6; From 7331be2627c1b19f2c94e423ce7dc74af2f2b8e0 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 8 Aug 2019 01:09:14 +0900 Subject: [PATCH 03/19] require perl-5.8.1 or later --- META.json | 2 +- lib/TheSchwartz.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/META.json b/META.json index 274c69f..43186d5 100644 --- a/META.json +++ b/META.json @@ -45,7 +45,7 @@ "Data::ObjectDriver" : "0.04", "Digest::MD5" : "0", "Storable" : "0", - "perl" : "5.008" + "perl" : "5.008001" } }, "test" : { diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index 9eb66e7..f843a79 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -1,7 +1,7 @@ # $Id$ package TheSchwartz; -use 5.008; +use 5.008001; use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); From a7d6a68d540c21721b888b8cee4fd58edeabf62c Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 8 Aug 2019 01:28:43 +0900 Subject: [PATCH 04/19] Checking in changes prior to tagging of version 1.13. Changelog diff is: diff --git a/Changes b/Changes index 31b1562..4c97373 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ {{$NEXT}} +1.13 2019-08-07T16:28:14Z + + - the module maintainer has been changed to Takumi Akiyama (AKIYM) + - fix tests fail without '.' in @INC. RT #124610 + - require perl-5.8.1 or later + 1.12 Mon Mar 30 2015 - Fix replace_job hanging & postgresql issues. RT #65712 - Add strict_remove_ability to prevent auto resetting of abilities. --- Changes | 6 ++++++ META.json | 2 +- lib/TheSchwartz.pm | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 31b1562..4c97373 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ {{$NEXT}} +1.13 2019-08-07T16:28:14Z + + - the module maintainer has been changed to Takumi Akiyama (AKIYM) + - fix tests fail without '.' in @INC. RT #124610 + - require perl-5.8.1 or later + 1.12 Mon Mar 30 2015 - Fix replace_job hanging & postgresql issues. RT #65712 - Add strict_remove_ability to prevent auto resetting of abilities. diff --git a/META.json b/META.json index 43186d5..5693e32 100644 --- a/META.json +++ b/META.json @@ -66,7 +66,7 @@ "web" : "https://github.com/akiym/TheSchwartz" } }, - "version" : "1.12", + "version" : "1.13", "x_authority" : "cpan:AKIYM", "x_contributors" : [ "Akira Sawada ", diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index f843a79..123c3a5 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -6,7 +6,7 @@ use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); -our $VERSION = "1.12"; +our $VERSION = "1.13"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 2fc1d68b98bf3f3e0d5af5c170fb1f2911b1c53b Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 17 Oct 2019 15:16:15 +0100 Subject: [PATCH 05/19] Added missing prereq Class::Accessor::Fast as suggested by CPANTS. --- cpanfile | 1 + 1 file changed, 1 insertion(+) diff --git a/cpanfile b/cpanfile index 57d0a56..70c6439 100644 --- a/cpanfile +++ b/cpanfile @@ -1,6 +1,7 @@ requires 'Data::ObjectDriver', '0.04'; requires 'Digest::MD5'; requires 'Storable'; +requires 'Class::Accessor::Fast'; on test => sub { requires 'Test::More'; From 7134fecc89df89bdfbfec6c0d5bdf32387022904 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Fri, 18 Oct 2019 02:52:18 +0900 Subject: [PATCH 06/19] Checking in changes prior to tagging of version 1.14. Changelog diff is: diff --git a/Changes b/Changes index 4c97373..780aea4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.14 2019-10-17T17:51:40Z + + - Added missing prereq Class::Accessor::Fast as suggested by CPANTS. GH#1 (@manwar++) + 1.13 2019-08-07T16:28:14Z - the module maintainer has been changed to Takumi Akiyama (AKIYM) --- Changes | 4 ++++ META.json | 4 +++- lib/TheSchwartz.pm | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 4c97373..780aea4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.14 2019-10-17T17:51:40Z + + - Added missing prereq Class::Accessor::Fast as suggested by CPANTS. GH#1 (@manwar++) + 1.13 2019-08-07T16:28:14Z - the module maintainer has been changed to Takumi Akiyama (AKIYM) diff --git a/META.json b/META.json index 5693e32..69ca570 100644 --- a/META.json +++ b/META.json @@ -42,6 +42,7 @@ }, "runtime" : { "requires" : { + "Class::Accessor::Fast" : "0", "Data::ObjectDriver" : "0.04", "Digest::MD5" : "0", "Storable" : "0", @@ -66,13 +67,14 @@ "web" : "https://github.com/akiym/TheSchwartz" } }, - "version" : "1.13", + "version" : "1.14", "x_authority" : "cpan:AKIYM", "x_contributors" : [ "Akira Sawada ", "Brad Fitzpatrick ", "Jeff Fearn ", "Jeff Fearn ", + "Mohammad S Anwar ", "Six Apart Ltd. ", "Takumi Akiyama " ], diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index 123c3a5..1c13412 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -6,7 +6,7 @@ use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); -our $VERSION = "1.13"; +our $VERSION = "1.14"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 739bc85fb92e9a2f1a412ff7d192bf6661b5b6b1 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Sun, 3 Nov 2019 15:09:06 +0900 Subject: [PATCH 07/19] add CI on Github Actions --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c8d6156 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: test +on: + push: + tags-ignore: + - '*' + pull_request: +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ['ubuntu-latest', 'macOS-latest'] + perl: [ '5.30', '5.28', '5.10', '5.8' ] + name: Perl ${{ matrix.perl }} on ${{ matrix.os }} + steps: + - uses: actions/checkout@v1 + - name: Setup perl + uses: shogo82148/actions-setup-perl@v1 + with: + perl-version: ${{ matrix.perl }} + - run: perl -V + - run: cpanm --installdeps . + - run: prove -lr --timer t xt From 0899ac03902e6797512514453db92ea5c0eaf634 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Sun, 3 Nov 2019 15:17:28 +0900 Subject: [PATCH 08/19] run CI on master branch --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8d6156..50f137a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,8 @@ name: test on: push: + branches: + - 'master' tags-ignore: - '*' pull_request: From ac1833ce3cb985ec1afe696072796f6821705e9e Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Tue, 28 Jan 2020 04:27:03 +0900 Subject: [PATCH 09/19] Clean up everything before tearing down the test databases to avoid permission errors under Win32 --- t/cleanup.t | 5 +++++ t/coalesce.t | 4 ++++ t/declined.t | 4 ++++ t/evenly-distribute.t | 4 ++++ t/fail-working-multiple.t | 4 ++++ t/grab_and_work_on.t | 4 ++++ t/insert-and-do.t | 2 ++ t/priority.t | 6 ++++++ t/replace-abort.t | 8 ++++++++ t/replace-with.t | 4 ++++ t/retry-delay.t | 2 ++ t/scoreboard.t | 2 ++ t/server-time.t | 4 ++++ t/work-before-funcids-exist.t | 4 ++++ 14 files changed, 57 insertions(+) diff --git a/t/cleanup.t b/t/cleanup.t index f13f23f..9b41f17 100644 --- a/t/cleanup.t +++ b/t/cleanup.t @@ -17,6 +17,8 @@ run_tests( 10, sub { my $client = test_client( dbs => ['ts1'] ); + + { my $dbh = DBI->connect( dsn_for("ts1"), $ENV{TS_DB_USER}, $ENV{TS_DB_PASS} ); $client->can_do("Worker::Fail"); @@ -63,6 +65,9 @@ run_tests( is( $min, 3, "error jobid is only the new one" ); } + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/coalesce.t b/t/coalesce.t index 0c152f4..4b5a24d 100644 --- a/t/coalesce.t +++ b/t/coalesce.t @@ -13,6 +13,7 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my @keys = qw(foo bar baz); my $n = 0; for ( 1 .. 10 ) { @@ -37,6 +38,9 @@ run_tests( } my $rv = eval { $client->work_once; }; ok( !$rv, "nothing to do now" ); + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/declined.t b/t/declined.t index 78dca2f..8d50be0 100644 --- a/t/declined.t +++ b/t/declined.t @@ -33,6 +33,8 @@ run_tests( "didn't get a job, because job is 'held' not retrying" ); } + $client->set_current_job(undef); + teardown_dbs('ts1'); } ); @@ -76,6 +78,8 @@ run_tests( } } + $client->set_current_job(undef); + teardown_dbs('ts2'); } ); diff --git a/t/evenly-distribute.t b/t/evenly-distribute.t index 3fc9082..2c1ddb7 100644 --- a/t/evenly-distribute.t +++ b/t/evenly-distribute.t @@ -14,6 +14,7 @@ run_tests( sub { my $client = test_client( dbs => [ 'ts1', 'ts2' ] ); + { my $n_jobs = 60; for ( 1 .. $n_jobs ) { my $handle = $client->insert("Worker::Foo"); @@ -54,6 +55,9 @@ run_tests( # difference in work done: my $workdiff = abs( $jobs1d - $jobs2d ); + } + + $client->set_current_job(undef); teardown_dbs( 'ts1', 'ts2' ); } diff --git a/t/fail-working-multiple.t b/t/fail-working-multiple.t index 94f07f7..e7bea19 100644 --- a/t/fail-working-multiple.t +++ b/t/fail-working-multiple.t @@ -13,6 +13,7 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my $job2h; for ( 1 .. 2 ) { my $job = TheSchwartz::Job->new( @@ -37,6 +38,9 @@ run_tests( # the second one should have failures: is( $job2h->failures, 1, "1 failure on second job" ); + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/grab_and_work_on.t b/t/grab_and_work_on.t index be99827..e190420 100644 --- a/t/grab_and_work_on.t +++ b/t/grab_and_work_on.t @@ -13,6 +13,7 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my $available = TheSchwartz::Job->new( funcname => 'Worker::Grabber', ); my $grabbed_until = time + 2; @@ -41,6 +42,9 @@ run_tests( $rv = $client->grab_and_work_on( $available_handle->as_string ); is scalar $available->failure_log, 0, "no errors"; ok( !$rv, "There is nothing to do for it now." ); + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/insert-and-do.t b/t/insert-and-do.t index 662abbd..7178c30 100644 --- a/t/insert-and-do.t +++ b/t/insert-and-do.t @@ -115,6 +115,8 @@ run_tests( ); } + $client->set_current_job(undef); + teardown_dbs('ts1'); } ); diff --git a/t/priority.t b/t/priority.t index 3ce6c6e..f53db08 100644 --- a/t/priority.t +++ b/t/priority.t @@ -53,6 +53,8 @@ run_tests( my $rv = eval { $client->work_once; }; ok( !$rv, "nothing to do now" ); + $client->set_current_job(undef); + teardown_dbs('ts1'); # test we get in jobid order for equal priority RT #99075 @@ -87,6 +89,8 @@ run_tests( $rv = eval { $client2->work_once; }; ok( !$rv, "nothing to do now 1-5" ); + $client2->set_current_job(undef); + teardown_dbs('ts2'); # test floor RT #50842 @@ -119,6 +123,8 @@ run_tests( $rv = eval { $client2->work_once; }; ok( !$rv, "sub-floor jobs remaining but you can't have them" ); + $client2->set_current_job(undef); + teardown_dbs('ts3'); $testnum = 0; } diff --git a/t/replace-abort.t b/t/replace-abort.t index 252bfb0..070c6b9 100644 --- a/t/replace-abort.t +++ b/t/replace-abort.t @@ -12,6 +12,7 @@ run_tests_pgsql(13, sub { my $client1 = test_client(dbs => ['ts1']); my $client2 = test_client(dbs => ['ts1']); + { my $driver = $client1->driver_for( ($client1->shuffled_databases)[0] ); my $dbh = $driver->rw_handle; @@ -137,6 +138,13 @@ run_tests_pgsql(13, sub { 0, 'Job 3 erneut abgearbeitet', ); + + } + + $client1->set_current_job(undef); + $client2->set_current_job(undef); + + teardown_dbs('ts1'); }); diff --git a/t/replace-with.t b/t/replace-with.t index 6887988..17ee4fd 100644 --- a/t/replace-with.t +++ b/t/replace-with.t @@ -13,6 +13,7 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my $handle = $client->insert( "Worker::Foo", { cluster => 'all' } ); ok($handle); @@ -31,6 +32,9 @@ run_tests( $job = $handle->job; $job->replace_with(); ok( !$handle->is_pending, "job no longer pending" ); + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/retry-delay.t b/t/retry-delay.t index fdda944..6146e36 100644 --- a/t/retry-delay.t +++ b/t/retry-delay.t @@ -42,6 +42,8 @@ run_tests( is( $handle->exit_status, 0, "job succeeded" ); } + $client->set_current_job(undef); + teardown_dbs('ts1'); } ); diff --git a/t/scoreboard.t b/t/scoreboard.t index bc197d0..bb04fd9 100644 --- a/t/scoreboard.t +++ b/t/scoreboard.t @@ -76,6 +76,8 @@ run_tests( 'Scoreboard file goes away when worker finishes' ); } + $client->set_current_job(undef); + teardown_dbs('ts1'); } ); diff --git a/t/server-time.t b/t/server-time.t index 47ded3a..d954cc6 100644 --- a/t/server-time.t +++ b/t/server-time.t @@ -13,11 +13,15 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my $driver = $client->driver_for( ( $client->shuffled_databases )[0] ); isa_ok $driver, 'Data::ObjectDriver::Driver::DBI'; cmp_ok $client->get_server_time($driver), '>', 0, 'got server time'; + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } diff --git a/t/work-before-funcids-exist.t b/t/work-before-funcids-exist.t index 17efbbc..b0dacc6 100644 --- a/t/work-before-funcids-exist.t +++ b/t/work-before-funcids-exist.t @@ -14,6 +14,7 @@ run_tests( sub { my $client = test_client( dbs => ['ts1'] ); + { my $handle = $client->insert("Worker::Dummy"); ok( $handle, "inserted job" ); @@ -23,6 +24,9 @@ run_tests( $client->work_until_done; ok( !$handle->is_pending, "job is done" ); + } + + $client->set_current_job(undef); teardown_dbs('ts1'); } From 155e3ca23abfb87ae2e73c982ccc3e3c7492aa85 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Tue, 28 Jan 2020 04:46:46 +0900 Subject: [PATCH 10/19] Perltidy --- t/cleanup.t | 97 ++++++----- t/coalesce.t | 48 +++--- t/declined.t | 2 +- t/evenly-distribute.t | 80 ++++----- t/fail-working-multiple.t | 50 +++--- t/grab_and_work_on.t | 56 +++--- t/insert-and-do.t | 2 +- t/replace-abort.t | 312 ++++++++++++++++++---------------- t/replace-with.t | 38 +++-- t/retry-delay.t | 2 +- t/scoreboard.t | 4 +- t/server-time.t | 9 +- t/work-before-funcids-exist.t | 14 +- 13 files changed, 370 insertions(+), 344 deletions(-) diff --git a/t/cleanup.t b/t/cleanup.t index 9b41f17..d50bdc0 100644 --- a/t/cleanup.t +++ b/t/cleanup.t @@ -19,52 +19,55 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $dbh = DBI->connect( dsn_for("ts1"), $ENV{TS_DB_USER}, - $ENV{TS_DB_PASS} ); - $client->can_do("Worker::Fail"); - $client->can_do("Worker::Complete"); - - # insert a job which will fail, then succeed. - { - my $handle = $client->insert("Worker::Fail"); - isa_ok $handle, 'TheSchwartz::JobHandle', "inserted job"; - - $client->work_until_done; - is( $handle->failures, 1, "job has failed once" ); - - my $min; - my $rows - = $dbh->selectrow_array("SELECT COUNT(*) FROM exitstatus"); - is( $rows, 1, "has 1 exitstatus row" ); - - ok( $client->insert("Worker::Complete"), - "inserting to-pass job" ); - $client->work_until_done; - $rows = $dbh->selectrow_array("SELECT COUNT(*) FROM exitstatus"); - is( $rows, 2, "has 2 exitstatus rows" ); - ( $rows, $min ) - = $dbh->selectrow_array( - "SELECT COUNT(*), MIN(jobid) FROM error"); - is( $rows, 1, "has 1 error rows" ); - is( $min, 1, "error jobid is the old one" ); - - # wait for exit status to pass - sleep 3; - - # now make another job fail to cleanup some errors - $handle = $client->insert("Worker::Fail"); - $client->work_until_done; - - $rows = $dbh->selectrow_array("SELECT COUNT(*) FROM exitstatus"); - is( $rows, 1, "1 exit status row now" ); - - ( $rows, $min ) - = $dbh->selectrow_array( - "SELECT COUNT(*), MIN(jobid) FROM error"); - is( $rows, 1, "has 1 error row still" ); - is( $min, 3, "error jobid is only the new one" ); - - } + my $dbh = DBI->connect( dsn_for("ts1"), $ENV{TS_DB_USER}, + $ENV{TS_DB_PASS} ); + $client->can_do("Worker::Fail"); + $client->can_do("Worker::Complete"); + + # insert a job which will fail, then succeed. + { + my $handle = $client->insert("Worker::Fail"); + isa_ok $handle, 'TheSchwartz::JobHandle', "inserted job"; + + $client->work_until_done; + is( $handle->failures, 1, "job has failed once" ); + + my $min; + my $rows + = $dbh->selectrow_array( + "SELECT COUNT(*) FROM exitstatus"); + is( $rows, 1, "has 1 exitstatus row" ); + + ok( $client->insert("Worker::Complete"), + "inserting to-pass job" ); + $client->work_until_done; + $rows = $dbh->selectrow_array( + "SELECT COUNT(*) FROM exitstatus"); + is( $rows, 2, "has 2 exitstatus rows" ); + ( $rows, $min ) + = $dbh->selectrow_array( + "SELECT COUNT(*), MIN(jobid) FROM error"); + is( $rows, 1, "has 1 error rows" ); + is( $min, 1, "error jobid is the old one" ); + + # wait for exit status to pass + sleep 3; + + # now make another job fail to cleanup some errors + $handle = $client->insert("Worker::Fail"); + $client->work_until_done; + + $rows = $dbh->selectrow_array( + "SELECT COUNT(*) FROM exitstatus"); + is( $rows, 1, "1 exit status row now" ); + + ( $rows, $min ) + = $dbh->selectrow_array( + "SELECT COUNT(*), MIN(jobid) FROM error"); + is( $rows, 1, "has 1 error row still" ); + is( $min, 3, "error jobid is only the new one" ); + + } } $client->set_current_job(undef); @@ -84,7 +87,7 @@ sub work { } sub keep_exit_status_for { - 1 + 1; } # keep exit status for 20 seconds after on_complete sub max_retries {0} diff --git a/t/coalesce.t b/t/coalesce.t index 4b5a24d..42072d8 100644 --- a/t/coalesce.t +++ b/t/coalesce.t @@ -14,30 +14,30 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my @keys = qw(foo bar baz); - my $n = 0; - for ( 1 .. 10 ) { - my $key = $keys[ $n++ % 3 ]; - my $job = TheSchwartz::Job->new( - funcname => 'Worker::CoalesceTest', - arg => { key => $key, num => $_ }, - coalesce => $key - ); - my $h = $client->insert($job); - ok( $h, "inserted $h ($_ = $key)" ); - } - - $client->reset_abilities; - $client->can_do("Worker::CoalesceTest"); - - Worker::CoalesceTest->set_client($client); - - for ( 1 .. 3 ) { + my @keys = qw(foo bar baz); + my $n = 0; + for ( 1 .. 10 ) { + my $key = $keys[ $n++ % 3 ]; + my $job = TheSchwartz::Job->new( + funcname => 'Worker::CoalesceTest', + arg => { key => $key, num => $_ }, + coalesce => $key + ); + my $h = $client->insert($job); + ok( $h, "inserted $h ($_ = $key)" ); + } + + $client->reset_abilities; + $client->can_do("Worker::CoalesceTest"); + + Worker::CoalesceTest->set_client($client); + + for ( 1 .. 3 ) { + my $rv = eval { $client->work_once; }; + ok( $rv, "did stuff" ); + } my $rv = eval { $client->work_once; }; - ok( $rv, "did stuff" ); - } - my $rv = eval { $client->work_once; }; - ok( !$rv, "nothing to do now" ); + ok( !$rv, "nothing to do now" ); } $client->set_current_job(undef); @@ -83,7 +83,7 @@ sub work { } sub keep_exit_status_for { - 20 + 20; } # keep exit status for 20 seconds after on_complete sub grab_for {10} diff --git a/t/declined.t b/t/declined.t index 8d50be0..798edfc 100644 --- a/t/declined.t +++ b/t/declined.t @@ -4,7 +4,7 @@ use warnings; require './t/lib/db-common.pl'; use TheSchwartz; -use Test::More tests => (5 + 21) * 3; +use Test::More tests => ( 5 + 21 ) * 3; our $decline = 1; diff --git a/t/evenly-distribute.t b/t/evenly-distribute.t index 2c1ddb7..9545a75 100644 --- a/t/evenly-distribute.t +++ b/t/evenly-distribute.t @@ -15,46 +15,46 @@ run_tests( my $client = test_client( dbs => [ 'ts1', 'ts2' ] ); { - my $n_jobs = 60; - for ( 1 .. $n_jobs ) { - my $handle = $client->insert("Worker::Foo"); - die unless $handle; - } - - my $db1 = DBI->connect( dsn_for("ts1"), $ENV{TS_DB_USER}, - $ENV{TS_DB_PASS} ); - my $db2 = DBI->connect( dsn_for("ts2"), $ENV{TS_DB_USER}, - $ENV{TS_DB_PASS} ); - die unless $db1 && $db2; - - my $jobs1 = $db1->selectrow_array("SELECT COUNT(*) FROM job"); - my $jobs2 = $db2->selectrow_array("SELECT COUNT(*) FROM job"); - is( $jobs1 + $jobs2, $n_jobs, "inserted all $n_jobs" ); - - ok( $jobs1 > $n_jobs / 4, - "at least a quarter of jobs went to db1 ($jobs1 / $n_jobs)" ); - ok( $jobs2 > $n_jobs / 4, - "at least a quarter of jobs went to db1 ($jobs2 / $n_jobs)" ); - - my $do_jobs = int( $n_jobs / 2 ); - $client->can_do("Worker::Foo"); - for ( 1 .. $do_jobs ) { - $client->work_once - or die; - } - - my $jobs1b = $db1->selectrow_array("SELECT COUNT(*) FROM job"); - my $jobs2b = $db2->selectrow_array("SELECT COUNT(*) FROM job"); - - my $remain_jobs = $n_jobs - $do_jobs; - is( $jobs1b + $jobs2b, $remain_jobs, "expected jobs remain" ); - - # deltas: how much work gone done each - my $jobs1d = $jobs1 - $jobs1b; - my $jobs2d = $jobs2 - $jobs2b; - - # difference in work done: - my $workdiff = abs( $jobs1d - $jobs2d ); + my $n_jobs = 60; + for ( 1 .. $n_jobs ) { + my $handle = $client->insert("Worker::Foo"); + die unless $handle; + } + + my $db1 = DBI->connect( dsn_for("ts1"), $ENV{TS_DB_USER}, + $ENV{TS_DB_PASS} ); + my $db2 = DBI->connect( dsn_for("ts2"), $ENV{TS_DB_USER}, + $ENV{TS_DB_PASS} ); + die unless $db1 && $db2; + + my $jobs1 = $db1->selectrow_array("SELECT COUNT(*) FROM job"); + my $jobs2 = $db2->selectrow_array("SELECT COUNT(*) FROM job"); + is( $jobs1 + $jobs2, $n_jobs, "inserted all $n_jobs" ); + + ok( $jobs1 > $n_jobs / 4, + "at least a quarter of jobs went to db1 ($jobs1 / $n_jobs)" ); + ok( $jobs2 > $n_jobs / 4, + "at least a quarter of jobs went to db1 ($jobs2 / $n_jobs)" ); + + my $do_jobs = int( $n_jobs / 2 ); + $client->can_do("Worker::Foo"); + for ( 1 .. $do_jobs ) { + $client->work_once + or die; + } + + my $jobs1b = $db1->selectrow_array("SELECT COUNT(*) FROM job"); + my $jobs2b = $db2->selectrow_array("SELECT COUNT(*) FROM job"); + + my $remain_jobs = $n_jobs - $do_jobs; + is( $jobs1b + $jobs2b, $remain_jobs, "expected jobs remain" ); + + # deltas: how much work gone done each + my $jobs1d = $jobs1 - $jobs1b; + my $jobs2d = $jobs2 - $jobs2b; + + # difference in work done: + my $workdiff = abs( $jobs1d - $jobs2d ); } $client->set_current_job(undef); diff --git a/t/fail-working-multiple.t b/t/fail-working-multiple.t index e7bea19..bca3a03 100644 --- a/t/fail-working-multiple.t +++ b/t/fail-working-multiple.t @@ -14,30 +14,30 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $job2h; - for ( 1 .. 2 ) { - my $job = TheSchwartz::Job->new( - funcname => 'Worker::CoalesceTest', - arg => { n => $_ }, - coalesce => "a$_", - ); - my $h = $client->insert($job); - $job2h = $h if $_ == 2; - ok( $h, "inserted $h" ); - } - - $client->reset_abilities; - $client->can_do("Worker::CoalesceTest"); - - my $job = $client->find_job_with_coalescing_prefix( - "Worker::CoalesceTest", "a1" ); - Worker::CoalesceTest->work_safely($job); - - # this one should have succeeded: - is( $job->handle->failures, 0, "no failures on first job" ); - - # the second one should have failures: - is( $job2h->failures, 1, "1 failure on second job" ); + my $job2h; + for ( 1 .. 2 ) { + my $job = TheSchwartz::Job->new( + funcname => 'Worker::CoalesceTest', + arg => { n => $_ }, + coalesce => "a$_", + ); + my $h = $client->insert($job); + $job2h = $h if $_ == 2; + ok( $h, "inserted $h" ); + } + + $client->reset_abilities; + $client->can_do("Worker::CoalesceTest"); + + my $job = $client->find_job_with_coalescing_prefix( + "Worker::CoalesceTest", "a1" ); + Worker::CoalesceTest->work_safely($job); + + # this one should have succeeded: + is( $job->handle->failures, 0, "no failures on first job" ); + + # the second one should have failures: + is( $job2h->failures, 1, "1 failure on second job" ); } $client->set_current_job(undef); @@ -62,7 +62,7 @@ sub work { } sub keep_exit_status_for { - 20 + 20; } # keep exit status for 20 seconds after on_complete sub grab_for {10} sub max_retries {1} diff --git a/t/grab_and_work_on.t b/t/grab_and_work_on.t index e190420..4272c95 100644 --- a/t/grab_and_work_on.t +++ b/t/grab_and_work_on.t @@ -14,34 +14,34 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $available - = TheSchwartz::Job->new( funcname => 'Worker::Grabber', ); - my $grabbed_until = time + 2; - my $grabbed = TheSchwartz::Job->new( - funcname => 'Worker::Grabber', - grabbed_until => $grabbed_until, - ); - my $available_handle = $client->insert($available); - my $grabbed_handle = $client->insert($grabbed); - - $client->reset_abilities; - $client->can_do("Worker::Grabber"); - - Worker::Grabber->set_client($client); - - my $rv = $client->grab_and_work_on( $grabbed_handle->as_string ); - ok( !$rv, "we couldn't grab it" ); - is scalar $grabbed->failure_log, 0, "no errors"; - $grabbed->refresh; - is $grabbed->grabbed_until, $grabbed_until, "Still grabbed"; - - $rv = $client->grab_and_work_on( $available_handle->as_string ); - is scalar $available->failure_log, 0, "no errors"; - ok( $rv, "we worked on it" ); - - $rv = $client->grab_and_work_on( $available_handle->as_string ); - is scalar $available->failure_log, 0, "no errors"; - ok( !$rv, "There is nothing to do for it now." ); + my $available + = TheSchwartz::Job->new( funcname => 'Worker::Grabber', ); + my $grabbed_until = time + 2; + my $grabbed = TheSchwartz::Job->new( + funcname => 'Worker::Grabber', + grabbed_until => $grabbed_until, + ); + my $available_handle = $client->insert($available); + my $grabbed_handle = $client->insert($grabbed); + + $client->reset_abilities; + $client->can_do("Worker::Grabber"); + + Worker::Grabber->set_client($client); + + my $rv = $client->grab_and_work_on( $grabbed_handle->as_string ); + ok( !$rv, "we couldn't grab it" ); + is scalar $grabbed->failure_log, 0, "no errors"; + $grabbed->refresh; + is $grabbed->grabbed_until, $grabbed_until, "Still grabbed"; + + $rv = $client->grab_and_work_on( $available_handle->as_string ); + is scalar $available->failure_log, 0, "no errors"; + ok( $rv, "we worked on it" ); + + $rv = $client->grab_and_work_on( $available_handle->as_string ); + is scalar $available->failure_log, 0, "no errors"; + ok( !$rv, "There is nothing to do for it now." ); } $client->set_current_job(undef); diff --git a/t/insert-and-do.t b/t/insert-and-do.t index 7178c30..4b6398b 100644 --- a/t/insert-and-do.t +++ b/t/insert-and-do.t @@ -170,7 +170,7 @@ sub work { } sub keep_exit_status_for { - 20 + 20; } # keep exit status for 20 seconds after on_complete sub grab_for {10} diff --git a/t/replace-abort.t b/t/replace-abort.t index 070c6b9..6f27dea 100644 --- a/t/replace-abort.t +++ b/t/replace-abort.t @@ -8,147 +8,165 @@ require './t/lib/db-common.pl'; use TheSchwartz; use Test::More tests => 13; -run_tests_pgsql(13, sub { - my $client1 = test_client(dbs => ['ts1']); - my $client2 = test_client(dbs => ['ts1']); - - { - my $driver = $client1->driver_for( ($client1->shuffled_databases)[0] ); - my $dbh = $driver->rw_handle; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey IN ('1','2','3','4','5');"), - 0, - 'namespace empty', - ); - - - $client1->can_do('Test::Job::Completed'); - $client2->can_do('Test::Job::Replace'); - -# job 1 - $client1->insert(TheSchwartz::Job->new( - funcname => 'Test::Job::Completed', - uniqkey => 1, - )); - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '1';"), - 1, - 'Job 1 gepostet', - ); - - -# Job 1 - $client1->work_once; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '1';"), - 0, - 'Job 1 abgearbeitet', - ); - -# Job 2 - $client2->insert(TheSchwartz::Job->new( - funcname => 'Test::Job::Replace', - uniqkey => 2, - arg => 3, - )); - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '2';"), - 1, - 'Job 2 gepostet', - ); - -# Job 2 - $client2->work_once; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '2';"), - 0, - 'Job 2 abgearbeitet', - ); - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';"), - 1, - 'Job 2 ersetzt durch Job 3', - ); - -# Job 4 - $client2->insert(TheSchwartz::Job->new( - funcname => 'Test::Job::Replace', - uniqkey => 4, - arg => 3, - )); - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';"), - 1, - 'Job 4 gepostet', - ); - -# Job 4 - $client2->work_once; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';"), - 1, - 'Job 4 abgebrochen', - ); - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';"), - 1, - 'Job 4 nicht durch Job 3 ersetzt', - ); - -# Job 3 - $client1->work_once; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';"), - 0, - 'Job 3 abgearbeitet', - ); - -# cleanup job.run_after & retry_at, so we dont have to wait - $dbh->do("UPDATE job SET run_after = 0 WHERE uniqkey = '4';"); - $client2->{retry_at} = {}; - -# Job 4 - $client2->work_once; - - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';"), - 0, - 'Job 4 abgearbeitet', - ); - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';"), - 1, - 'Job 4 ersetzt durch Job 3', - ); - -# Job 5 - $client1->work_once; - - is( - query_sql($dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';"), - 0, - 'Job 3 erneut abgearbeitet', - ); - +run_tests_pgsql( + 13, + sub { + my $client1 = test_client( dbs => ['ts1'] ); + my $client2 = test_client( dbs => ['ts1'] ); + + { + my $driver + = $client1->driver_for( ( $client1->shuffled_databases )[0] ); + my $dbh = $driver->rw_handle; + + is( query_sql( + $dbh, + "SELECT COUNT(*) FROM job WHERE uniqkey IN ('1','2','3','4','5');" + ), + 0, + 'namespace empty', + ); + + $client1->can_do('Test::Job::Completed'); + $client2->can_do('Test::Job::Replace'); + + # job 1 + $client1->insert( + TheSchwartz::Job->new( + funcname => 'Test::Job::Completed', + uniqkey => 1, + ) + ); + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '1';" + ), + 1, + 'Job 1 gepostet', + ); + + # Job 1 + $client1->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '1';" + ), + 0, + 'Job 1 abgearbeitet', + ); + + # Job 2 + $client2->insert( + TheSchwartz::Job->new( + funcname => 'Test::Job::Replace', + uniqkey => 2, + arg => 3, + ) + ); + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '2';" + ), + 1, + 'Job 2 gepostet', + ); + + # Job 2 + $client2->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '2';" + ), + 0, + 'Job 2 abgearbeitet', + ); + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';" + ), + 1, + 'Job 2 ersetzt durch Job 3', + ); + + # Job 4 + $client2->insert( + TheSchwartz::Job->new( + funcname => 'Test::Job::Replace', + uniqkey => 4, + arg => 3, + ) + ); + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';" + ), + 1, + 'Job 4 gepostet', + ); + + # Job 4 + $client2->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';" + ), + 1, + 'Job 4 abgebrochen', + ); + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';" + ), + 1, + 'Job 4 nicht durch Job 3 ersetzt', + ); + + # Job 3 + $client1->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';" + ), + 0, + 'Job 3 abgearbeitet', + ); + + # cleanup job.run_after & retry_at, so we dont have to wait + $dbh->do("UPDATE job SET run_after = 0 WHERE uniqkey = '4';"); + $client2->{retry_at} = {}; + + # Job 4 + $client2->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '4';" + ), + 0, + 'Job 4 abgearbeitet', + ); + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';" + ), + 1, + 'Job 4 ersetzt durch Job 3', + ); + + # Job 5 + $client1->work_once; + + is( query_sql( + $dbh, "SELECT COUNT(*) FROM job WHERE uniqkey = '3';" + ), + 0, + 'Job 3 erneut abgearbeitet', + ); + + } + + $client1->set_current_job(undef); + $client2->set_current_job(undef); + + teardown_dbs('ts1'); } - - $client1->set_current_job(undef); - $client2->set_current_job(undef); - - teardown_dbs('ts1'); -}); - - - +); # TheSchwartz Worker/Jobs package Test::Job::Completed; @@ -156,7 +174,7 @@ package Test::Job::Completed; use base qw(TheSchwartz::Worker); sub work { - my ($client, $job) = @_; + my ( $client, $job ) = @_; $job->completed; } sub max_retries { 10; } @@ -166,11 +184,13 @@ package Test::Job::Replace; use base qw(TheSchwartz::Worker); sub work { - my ($client, $job) = @_; - $job->replace_with(TheSchwartz::Job->new( - funcname => 'Test::Job::Completed', - uniqkey => $job->arg, - )); + my ( $client, $job ) = @_; + $job->replace_with( + TheSchwartz::Job->new( + funcname => 'Test::Job::Completed', + uniqkey => $job->arg, + ) + ); } sub max_retries { 10; } diff --git a/t/replace-with.t b/t/replace-with.t index 17ee4fd..ba09972 100644 --- a/t/replace-with.t +++ b/t/replace-with.t @@ -14,24 +14,26 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $handle = $client->insert( "Worker::Foo", { cluster => 'all' } ); - ok($handle); - - my $job = Worker::Foo->grab_job($client); - ok( $job, "no addition jobs to be grabbed" ); - - Worker::Foo->work_safely($job); - - $client->can_do("Worker::Foo"); - $client->work_until_done; # should process 5 jobs. - - # finish a job by replacing it with nothing - $handle - = $client->insert( "Worker::Foo", { cluster => 'gibberish' } ); - ok( $handle->is_pending, "job is still pending" ); - $job = $handle->job; - $job->replace_with(); - ok( !$handle->is_pending, "job no longer pending" ); + my $handle + = $client->insert( "Worker::Foo", { cluster => 'all' } ); + ok($handle); + + my $job = Worker::Foo->grab_job($client); + ok( $job, "no addition jobs to be grabbed" ); + + Worker::Foo->work_safely($job); + + $client->can_do("Worker::Foo"); + $client->work_until_done; # should process 5 jobs. + + # finish a job by replacing it with nothing + $handle + = $client->insert( "Worker::Foo", + { cluster => 'gibberish' } ); + ok( $handle->is_pending, "job is still pending" ); + $job = $handle->job; + $job->replace_with(); + ok( !$handle->is_pending, "job no longer pending" ); } $client->set_current_job(undef); diff --git a/t/retry-delay.t b/t/retry-delay.t index 6146e36..96afdae 100644 --- a/t/retry-delay.t +++ b/t/retry-delay.t @@ -65,7 +65,7 @@ sub work { } sub keep_exit_status_for { - 20 + 20; } # keep exit status for 20 seconds after on_complete sub max_retries {2} diff --git a/t/scoreboard.t b/t/scoreboard.t index bb04fd9..b26e2f1 100644 --- a/t/scoreboard.t +++ b/t/scoreboard.t @@ -33,7 +33,7 @@ run_tests( pass => $ENV{TS_DB_PASS}, prefix => $pfx, } - } @$dbs + } @$dbs ] ); @@ -62,7 +62,7 @@ run_tests( my %info = map { chomp; /^([^=]+)=(.*)$/ } ; close(FH); - ok( $info{pid} == $$, 'Has our PID' ); + ok( $info{pid} == $$, 'Has our PID' ); ok( $info{funcname} eq 'Worker::Addition', 'Has our funcname' ); ok( $info{started} =~ /\d+/, 'Started time is a number' ); ok( $info{started} <= time, 'Started time is in the past' ); diff --git a/t/server-time.t b/t/server-time.t index d954cc6..1ef1d42 100644 --- a/t/server-time.t +++ b/t/server-time.t @@ -14,11 +14,12 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $driver - = $client->driver_for( ( $client->shuffled_databases )[0] ); - isa_ok $driver, 'Data::ObjectDriver::Driver::DBI'; + my $driver + = $client->driver_for( ( $client->shuffled_databases )[0] ); + isa_ok $driver, 'Data::ObjectDriver::Driver::DBI'; - cmp_ok $client->get_server_time($driver), '>', 0, 'got server time'; + cmp_ok $client->get_server_time($driver), '>', 0, + 'got server time'; } $client->set_current_job(undef); diff --git a/t/work-before-funcids-exist.t b/t/work-before-funcids-exist.t index b0dacc6..6468df3 100644 --- a/t/work-before-funcids-exist.t +++ b/t/work-before-funcids-exist.t @@ -15,15 +15,15 @@ run_tests( my $client = test_client( dbs => ['ts1'] ); { - my $handle = $client->insert("Worker::Dummy"); - ok( $handle, "inserted job" ); + my $handle = $client->insert("Worker::Dummy"); + ok( $handle, "inserted job" ); - $client->can_do("Worker::Dummy"); - $client->can_do("Worker::Dummy2"); - $client->can_do("Worker::Dummy3"); - $client->work_until_done; + $client->can_do("Worker::Dummy"); + $client->can_do("Worker::Dummy2"); + $client->can_do("Worker::Dummy3"); + $client->work_until_done; - ok( !$handle->is_pending, "job is done" ); + ok( !$handle->is_pending, "job is done" ); } $client->set_current_job(undef); From 9816c169d0460b3c3075cfd21d8bed8466d8cfd2 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Tue, 28 Jan 2020 05:26:51 +0900 Subject: [PATCH 11/19] Respect volume --- t/scoreboard.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/scoreboard.t b/t/scoreboard.t index b26e2f1..d0429d4 100644 --- a/t/scoreboard.t +++ b/t/scoreboard.t @@ -39,9 +39,10 @@ run_tests( my $sb_file = $client->scoreboard; { - ( undef, my ( $sb_dir, $sb_name ) ) + my ( $sb_volume, $sb_dir, $sb_name ) = File::Spec->splitpath($sb_file); - ok( -e $sb_dir, "Looking for dir $sb_dir" ); + ok( -e File::Spec->catpath( $sb_volume, $sb_dir ), + "Looking for dir $sb_dir" ); } { From c2053526ae8fbc6327a6d51882b58c26baf239ab Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Tue, 28 Jan 2020 14:40:41 +0900 Subject: [PATCH 12/19] add windows-latest --- .github/workflows/test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50f137a..80d4e7b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,8 +11,15 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: ['ubuntu-latest', 'macOS-latest'] + os: ['ubuntu-latest', 'macOS-latest', 'windows-latest'] perl: [ '5.30', '5.28', '5.10', '5.8' ] + exclude: + # not supported on actions-setup-perl + - os: windows-latest + perl: '5.10' + # installing Module::Build::Tiny failed + - os: windows-latest + perl: '5.8' name: Perl ${{ matrix.perl }} on ${{ matrix.os }} steps: - uses: actions/checkout@v1 From 79f715ee79c1489c6347553063c681b37c5c2dab Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Tue, 28 Jan 2020 15:21:47 +0900 Subject: [PATCH 13/19] Checking in changes prior to tagging of version 1.15. Changelog diff is: diff --git a/Changes b/Changes index 780aea4..d95964d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.15 2020-01-28T06:19:54Z + + - Fix tests on win32 GH#4 (@charsbar++) + 1.14 2019-10-17T17:51:40Z - Added missing prereq Class::Accessor::Fast as suggested by CPANTS. GH#1 (@manwar++) --- Changes | 4 ++++ META.json | 5 +++-- lib/TheSchwartz.pm | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 780aea4..d95964d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.15 2020-01-28T06:19:54Z + + - Fix tests on win32 GH#4 (@charsbar++) + 1.14 2019-10-17T17:51:40Z - Added missing prereq Class::Accessor::Fast as suggested by CPANTS. GH#1 (@manwar++) diff --git a/META.json b/META.json index 69ca570..89660cc 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ ", Six Apart Ltd, cpan@sixapart.com. All" ], "dynamic_config" : 0, - "generated_by" : "Minilla/v3.1.5, CPAN::Meta::Converter version 2.150010", + "generated_by" : "Minilla/v3.1.8, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -67,13 +67,14 @@ "web" : "https://github.com/akiym/TheSchwartz" } }, - "version" : "1.14", + "version" : "1.15", "x_authority" : "cpan:AKIYM", "x_contributors" : [ "Akira Sawada ", "Brad Fitzpatrick ", "Jeff Fearn ", "Jeff Fearn ", + "Kenichi Ishigaki ", "Mohammad S Anwar ", "Six Apart Ltd. ", "Takumi Akiyama " diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index 1c13412..c57d8c3 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -6,7 +6,7 @@ use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); -our $VERSION = "1.14"; +our $VERSION = "1.15"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 52124ad873a720a1194692775382067fcd7ad29e Mon Sep 17 00:00:00 2001 From: Keita Jamadam Sugama Date: Fri, 16 Jul 2021 06:44:18 +0900 Subject: [PATCH 14/19] Add ability to disable job randomization --- lib/TheSchwartz.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index c57d8c3..2b4de05 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -27,6 +27,7 @@ our $T_LOST_RACE; ## Number of jobs to fetch at a time in find_job_for_workers. our $FIND_JOB_BATCH_SIZE = 50; +our $RANDOMIZE_JOBS = 1; sub new { my TheSchwartz $client = shift; @@ -400,7 +401,7 @@ sub _grab_a_job { my $driver = $client->driver_for($hashdsn); ## Got some jobs! Randomize them to avoid contention between workers. - my @jobs = shuffle(@_); + my @jobs = $RANDOMIZE_JOBS ? shuffle(@_) : @_; JOB: while ( my $job = shift @jobs ) { From d0ec935d45eadeaea8bbdf4ee52cd07d75862e4a Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Fri, 16 Jul 2021 16:50:36 +0900 Subject: [PATCH 15/19] Checking in changes prior to tagging of version 1.16. Changelog diff is: diff --git a/Changes b/Changes index d95964d..77c29d9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.16 2021-07-16T07:49:43Z + + - Add ability to disable job randomization GH#9 (@jamadam++) + 1.15 2020-01-28T06:19:54Z - Fix tests on win32 GH#4 (@charsbar++) --- Changes | 4 ++++ META.json | 5 +++-- README.md | 2 +- lib/TheSchwartz.pm | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index d95964d..77c29d9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.16 2021-07-16T07:49:43Z + + - Add ability to disable job randomization GH#9 (@jamadam++) + 1.15 2020-01-28T06:19:54Z - Fix tests on win32 GH#4 (@charsbar++) diff --git a/META.json b/META.json index 89660cc..1308b03 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ ", Six Apart Ltd, cpan@sixapart.com. All" ], "dynamic_config" : 0, - "generated_by" : "Minilla/v3.1.8, CPAN::Meta::Converter version 2.150010", + "generated_by" : "Minilla/v3.1.11, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -67,13 +67,14 @@ "web" : "https://github.com/akiym/TheSchwartz" } }, - "version" : "1.15", + "version" : "1.16", "x_authority" : "cpan:AKIYM", "x_contributors" : [ "Akira Sawada ", "Brad Fitzpatrick ", "Jeff Fearn ", "Jeff Fearn ", + "Keita Jamadam Sugama ", "Kenichi Ishigaki ", "Mohammad S Anwar ", "Six Apart Ltd. ", diff --git a/README.md b/README.md index 1f2e6f8..4c1ef93 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ Given a job handle (a scalar string) _$handle_, runs the job, then returns. ## `$client->grab_and_work_on($handle)` -Similar to [$client->work\_on($handle)](https://metacpan.org/pod/$client->work_on\($handle\)), except that the job will be grabbed +Similar to [$client->work\_on($handle)](https://metacpan.org/pod/%24client-%3Ework_on%28%24handle%29), except that the job will be grabbed before being run. It guarantees that only one worker will work on it (at least in the `grab_for` interval). diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index 2b4de05..7cf989d 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -6,7 +6,7 @@ use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); -our $VERSION = "1.15"; +our $VERSION = "1.16"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 2d91b74c3e3afd725f95a99ef9313a9de8cafa70 Mon Sep 17 00:00:00 2001 From: Todd Wade Date: Sat, 11 Dec 2021 20:09:12 -0500 Subject: [PATCH 16/19] 'Not an ARRAY reference' in DBSet::add for at least v5.16.3 Constructor makes a hashref but DBSet::push uses it as an array This change makes the object data type an arrayref instead of hashref so that ::push works and schwartzmon can run again --- script/schwartzmon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/schwartzmon b/script/schwartzmon index ea6eab9..23ef88c 100755 --- a/script/schwartzmon +++ b/script/schwartzmon @@ -249,7 +249,7 @@ package DBSet; sub new { my ( $this, $args ) = @_; my $class = ref($this) || $this; - return bless {}, $class; + return bless [], $class; } sub add { From 7bad5e66097588bb7f25dda237252265e540fcd5 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 30 Dec 2021 22:23:47 +0900 Subject: [PATCH 17/19] Checking in changes prior to tagging of version 1.17. Changelog diff is: diff --git a/Changes b/Changes index 77c29d9..c609fe4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.17 2021-12-30T13:21:45Z + + - schwartzmon: 'Not an ARRAY reference' in DBSet::add for at least v5.16.3 GH#12 (@trwww++) + 1.16 2021-07-16T07:49:43Z - Add ability to disable job randomization GH#9 (@jamadam++) --- Changes | 4 ++++ META.json | 7 ++++--- lib/TheSchwartz.pm | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 77c29d9..c609fe4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ {{$NEXT}} +1.17 2021-12-30T13:21:45Z + + - schwartzmon: 'Not an ARRAY reference' in DBSet::add for at least v5.16.3 GH#12 (@trwww++) + 1.16 2021-07-16T07:49:43Z - Add ability to disable job randomization GH#9 (@jamadam++) diff --git a/META.json b/META.json index 1308b03..3127414 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ ", Six Apart Ltd, cpan@sixapart.com. All" ], "dynamic_config" : 0, - "generated_by" : "Minilla/v3.1.11, CPAN::Meta::Converter version 2.150010", + "generated_by" : "Minilla/v3.1.12, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -67,7 +67,7 @@ "web" : "https://github.com/akiym/TheSchwartz" } }, - "version" : "1.16", + "version" : "1.17", "x_authority" : "cpan:AKIYM", "x_contributors" : [ "Akira Sawada ", @@ -78,7 +78,8 @@ "Kenichi Ishigaki ", "Mohammad S Anwar ", "Six Apart Ltd. ", - "Takumi Akiyama " + "Takumi Akiyama ", + "Todd Wade " ], "x_serialization_backend" : "JSON::PP version 4.04", "x_static_install" : 1 diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index 7cf989d..8a1d5a8 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -6,7 +6,7 @@ use strict; use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize floor batch_size strict_remove_ability); -our $VERSION = "1.16"; +our $VERSION = "1.17"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 3b2c7517b892b35c4d94ee46a3bde5f0bfa59881 Mon Sep 17 00:00:00 2001 From: Akira Sawada Date: Mon, 12 Jun 2023 15:47:43 +0900 Subject: [PATCH 18/19] Bump version --- lib/TheSchwartz.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/TheSchwartz.pm b/lib/TheSchwartz.pm index ca3d345..f89a43f 100644 --- a/lib/TheSchwartz.pm +++ b/lib/TheSchwartz.pm @@ -10,7 +10,7 @@ use fields qw( grab_and_fetch floor batch_size strict_remove_ability ); -our $VERSION = "1.17"; +our $VERSION = "1.18"; use Carp qw( croak ); use Data::ObjectDriver::Errors; From 72c9af72320d9365cdeb29e9411d7880d4abc7f7 Mon Sep 17 00:00:00 2001 From: Akira Sawada Date: Mon, 12 Jun 2023 15:52:12 +0900 Subject: [PATCH 19/19] It seems TAP::Harness is not installable now --- .github/workflows/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80d4e7b..72f82ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,16 +10,14 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: os: ['ubuntu-latest', 'macOS-latest', 'windows-latest'] - perl: [ '5.30', '5.28', '5.10', '5.8' ] + perl: [ '5.30', '5.28', '5.10' ] exclude: # not supported on actions-setup-perl - os: windows-latest perl: '5.10' - # installing Module::Build::Tiny failed - - os: windows-latest - perl: '5.8' name: Perl ${{ matrix.perl }} on ${{ matrix.os }} steps: - uses: actions/checkout@v1