Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
33beadde
Commit
33beadde
authored
15 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#698356 alex_b: Refactor and clean up FeedsScheduler::work() to allow more
scheduled tasks than 'import' and 'expire'.
parent
ba2fe1ed
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.txt
+6
-0
6 additions, 0 deletions
CHANGELOG.txt
includes/FeedsImporter.inc
+39
-9
39 additions, 9 deletions
includes/FeedsImporter.inc
includes/FeedsScheduler.inc
+8
-36
8 additions, 36 deletions
includes/FeedsScheduler.inc
with
53 additions
and
45 deletions
CHANGELOG.txt
+
6
−
0
View file @
33beadde
// $Id$
Feeds 6.x 1.0 xxxxx xx, xxxx-xx-xx
----------------------------------
- #698356 alex_b: Refactor and clean up FeedsScheduler::work() to allow more
scheduled tasks than 'import' and 'expire'.
Feeds 6.x 1.0 Alpha 10, 2010-01-25
----------------------------------
...
...
This diff is collapsed.
Click to expand it.
includes/FeedsImporter.inc
+
39
−
9
View file @
33beadde
...
...
@@ -72,22 +72,52 @@ class FeedsImporter extends FeedsConfigurable {
}
}
/**
* Callback for scheduler to invoke task. Do not execute if this importer is
* not persistent at all.
*
* @param $feed_info
* FeedsScheduler feed infor array.
*
* @see FeedsScheduler::work().
*/
public
function
work
(
$feed_info
)
{
if
(
$this
->
export_type
==
FEEDS_EXPORT_NONE
)
{
return
;
}
switch
(
$feed_info
[
'callback'
])
{
case
'import'
:
feeds_source
(
$feed_info
[
'importer_id'
],
$feed_info
[
'feed_nid'
])
->
import
();
break
;
case
'expire'
:
$this
->
expire
();
break
;
}
}
/**
* Get the refresh period for import() or expire().
*/
public
function
getSchedulePeriod
(
$callback
)
{
if
(
$callback
==
'import'
)
{
return
$this
->
config
[
'import_period'
];
}
if
(
$callback
==
'expire'
)
{
// If a processor has expiry time set, run expiry every hour.
if
(
FEEDS_EXPIRE_NEVER
!=
$this
->
processor
->
expiryTime
())
{
return
3600
;
}
return
FEEDS_SCHEDULE_NEVER
;
switch
(
$callback
)
{
case
'import'
:
return
$this
->
config
[
'import_period'
];
case
'expire'
:
// If a processor has expiry time set, run expiry every hour.
if
(
FEEDS_EXPIRE_NEVER
!=
$this
->
processor
->
expiryTime
())
{
return
3600
;
}
return
FEEDS_SCHEDULE_NEVER
;
}
}
/**
* Expose available schedule callbacks.
*/
public
function
getScheduleCallbacks
()
{
return
array
(
'import'
,
'expire'
);
}
/**
* Save configuration.
*/
...
...
This diff is collapsed.
Click to expand it.
includes/FeedsScheduler.inc
+
8
−
36
View file @
33beadde
...
...
@@ -85,8 +85,6 @@ class FeedsScheduler implements FeedsSchedulerInterface {
*
* If drupal_queue is present, only pushes refresh tasks to queue and
* returns. If drupal_queue is not available, works off tasks.
*
* @todo: Make import/expire agnostic, define general job callback interface.
*/
public
function
cron
()
{
...
...
@@ -113,7 +111,7 @@ class FeedsScheduler implements FeedsSchedulerInterface {
// Iterate over feed configurations, pick $num feeds for each
// configuration, push to queue or refresh feeds.
foreach
(
$importers
as
$importer
)
{
foreach
(
array
(
'import'
,
'expire'
)
as
$callback
)
{
foreach
(
$importer
->
getScheduleCallbacks
(
)
as
$callback
)
{
// Check whether jobs are scheduled.
$period
=
$importer
->
getSchedulePeriod
(
$callback
);
...
...
@@ -188,42 +186,16 @@ class FeedsScheduler implements FeedsSchedulerInterface {
*
* Used as worker callback invoked from feeds_scheduler_refresh() or
* if drupal_queue is not enabled, directly from $this->cron().
*
* @todo: Make import/expire agnostic, define general job callback interface.
*/
public
function
work
(
$feed_info
)
{
$importer
=
feeds_importer
(
$feed_info
[
'importer_id'
]);
// Only refresh if feed is actually in DB or in default configuration.
if
(
$importer
->
export_type
!=
FEEDS_EXPORT_NONE
)
{
// Remove scheduled flag, if we fail after this we'd like to try again
// next time around.
$this
->
unflag
(
$feed_info
[
'importer_id'
],
$feed_info
[
'callback'
],
$feed_info
[
'feed_nid'
]);
// There are 2 possible callbacks: expire or 'import'.
if
(
$feed_info
[
'callback'
]
==
'expire'
)
{
try
{
$importer
->
expire
();
}
catch
(
Exception
$e
)
{
watchdog
(
'FeedsScheduler'
,
$e
->
getMessage
(),
array
(),
WATCHDOG_ERROR
);
}
}
elseif
(
$feed_info
[
'callback'
]
==
'import'
)
{
// Import feed if source is available.
$source
=
feeds_source
(
$importer
->
id
,
$feed_info
[
'feed_nid'
]);
if
(
$source
->
export_type
&
FEEDS_EXPORT_NONE
)
{
watchdog
(
'FeedsScheduler'
,
'Expected source information in database for '
.
$importer
->
id
.
'/'
.
$feed_info
[
'feed_nid'
]
.
'. Could not find any.'
,
array
(),
WATCHDOG_ERROR
);
return
;
}
try
{
$source
->
import
();
}
catch
(
Exception
$e
)
{
watchdog
(
'FeedsScheduler'
,
$e
->
getMessage
(),
array
(),
WATCHDOG_ERROR
);
}
}
// Remove scheduled flag, if we fail after this we'd like to try again asap.
$this
->
unflag
(
$feed_info
[
'importer_id'
],
$feed_info
[
'callback'
],
$feed_info
[
'feed_nid'
]);
try
{
$importer
->
work
(
$feed_info
);
}
catch
(
Exception
$e
)
{
watchdog
(
'FeedsScheduler'
,
$e
->
getMessage
(),
array
(),
WATCHDOG_ERROR
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment